CustomTiles: add a custom long press PendingIntent
Ref: CYNGNOS-1602 Change-Id: Id0cca88fabb091dcf0fbad2ae24416fa1c0af83e Signed-off-by: Roman Birg <roman@cyngn.com>
This commit is contained in:
parent
5400b2f30e
commit
8d4920022f
@ -53,6 +53,15 @@ public class CustomTile implements Parcelable {
|
||||
**/
|
||||
public PendingIntent onClick;
|
||||
|
||||
/**
|
||||
* An optional intent to execute when the custom tile entry is long clicked. If
|
||||
* this is an activity, it must include the
|
||||
* {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires
|
||||
* that you take care of task management. Activities will also automatically trigger
|
||||
* the host panel to automatically collapse after executing the pending intent.
|
||||
**/
|
||||
public PendingIntent onLongClick;
|
||||
|
||||
/**
|
||||
* An optional settings intent to execute when the custom tile's detail is shown
|
||||
* If this is an activity, it must include the
|
||||
@ -162,6 +171,12 @@ public class CustomTile implements Parcelable {
|
||||
this.sensitiveData = (parcel.readInt() == 1);
|
||||
}
|
||||
|
||||
if (parcelableVersion >= Build.CM_VERSION_CODES.DRAGON_FRUIT) {
|
||||
if (parcel.readInt() != 0) {
|
||||
this.onLongClick = PendingIntent.CREATOR.createFromParcel(parcel);
|
||||
}
|
||||
}
|
||||
|
||||
parcel.setDataPosition(startPosition + parcelableSize);
|
||||
}
|
||||
|
||||
@ -196,6 +211,9 @@ public class CustomTile implements Parcelable {
|
||||
if (onClick != null) {
|
||||
b.append("onClick=" + onClick.toString() + NEW_LINE);
|
||||
}
|
||||
if (onLongClick != null) {
|
||||
b.append("onLongClick=" + onLongClick.toString() + NEW_LINE);
|
||||
}
|
||||
if (onSettingsClick != null) {
|
||||
b.append("onSettingsClick=" + onSettingsClick.toString() + NEW_LINE);
|
||||
}
|
||||
@ -229,6 +247,7 @@ public class CustomTile implements Parcelable {
|
||||
public void cloneInto(CustomTile that) {
|
||||
that.resourcesPackageName = this.resourcesPackageName;
|
||||
that.onClick = this.onClick;
|
||||
that.onLongClick = this.onLongClick;
|
||||
that.onSettingsClick = this.onSettingsClick;
|
||||
that.onClickUri = this.onClickUri;
|
||||
that.label = this.label;
|
||||
@ -314,6 +333,14 @@ public class CustomTile implements Parcelable {
|
||||
}
|
||||
out.writeInt(sensitiveData ? 1 : 0);
|
||||
|
||||
// ==== DRAGONFRUIT ====
|
||||
if (onLongClick != null) {
|
||||
out.writeInt(1);
|
||||
onLongClick.writeToParcel(out, 0);
|
||||
} else {
|
||||
out.writeInt(0);
|
||||
}
|
||||
|
||||
// Go back and write size
|
||||
int parcelableSize = out.dataPosition() - startPosition;
|
||||
out.setDataPosition(sizePosition);
|
||||
@ -907,6 +934,7 @@ public class CustomTile implements Parcelable {
|
||||
*/
|
||||
public static class Builder {
|
||||
private PendingIntent mOnClick;
|
||||
private PendingIntent mOnLongClick;
|
||||
private Intent mOnSettingsClick;
|
||||
private Uri mOnClickUri;
|
||||
private String mLabel;
|
||||
@ -976,6 +1004,17 @@ public class CustomTile implements Parcelable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a {@link android.app.PendingIntent} to be fired on custom tile long press.
|
||||
* Note: if this is an activity, the host panel will automatically collapse.
|
||||
* @param intent
|
||||
* @return {@link cyanogenmod.app.CustomTile.Builder}
|
||||
*/
|
||||
public Builder setOnLongClickIntent(PendingIntent intent) {
|
||||
mOnLongClick = intent;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a settings {@link android.content.Intent} to be fired on custom
|
||||
* tile detail pane click
|
||||
@ -1080,6 +1119,7 @@ public class CustomTile implements Parcelable {
|
||||
CustomTile tile = new CustomTile();
|
||||
tile.resourcesPackageName = mContext.getPackageName();
|
||||
tile.onClick = mOnClick;
|
||||
tile.onLongClick = mOnLongClick;
|
||||
tile.onSettingsClick = mOnSettingsClick;
|
||||
tile.onClickUri = mOnClickUri;
|
||||
tile.label = mLabel;
|
||||
|
@ -148,6 +148,21 @@ public class CMStatusBarTest extends TestActivity {
|
||||
}
|
||||
},
|
||||
|
||||
new Test("test publish tile with long press") {
|
||||
public void run() {
|
||||
CustomTile customTile = new CustomTile.Builder(CMStatusBarTest.this)
|
||||
.setLabel("Test Long press From SDK")
|
||||
.setIcon(R.drawable.ic_launcher)
|
||||
.setOnLongClickIntent(PendingIntent.getActivity(CMStatusBarTest.this, 0,
|
||||
new Intent(CMStatusBarTest.this,DummySettings.class)
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0))
|
||||
.setContentDescription("Content description")
|
||||
.build();
|
||||
CMStatusBarManager.getInstance(CMStatusBarTest.this)
|
||||
.publishTile(CUSTOM_TILE_SETTINGS_ID, customTile);
|
||||
}
|
||||
},
|
||||
|
||||
new Test("test publish tile with delete intent") {
|
||||
public void run() {
|
||||
Intent intent = new Intent(CMStatusBarTest.this, DummySettings.class);
|
||||
|
@ -57,6 +57,17 @@ public class CustomTileBuilderTest extends AndroidTestCase {
|
||||
assertEquals(pendingIntent, customTile.onClick);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testCustomTileBuilderOnLongClickIntent() {
|
||||
Intent intent = new Intent(Intent.ACTION_DIAL);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
|
||||
CustomTile customTile = new CustomTile.Builder(mContext)
|
||||
.setOnLongClickIntent(pendingIntent)
|
||||
.build();
|
||||
assertNotNull(customTile.onLongClick);
|
||||
assertEquals(pendingIntent, customTile.onLongClick);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testCustomTileBuilderOnSettingsClickIntent() {
|
||||
Intent intent = new Intent(mContext, DummySettings.class);
|
||||
|
@ -64,6 +64,29 @@ public class CustomTileTest extends AndroidTestCase {
|
||||
fromParcel.onClick.getIntent().toString());
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testCustomTileOnLongiClickIntentUnravelFromParcel() {
|
||||
Intent intent = new Intent(Intent.ACTION_DIAL);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
|
||||
CustomTile expectedCustomTile = new CustomTile.Builder(mContext)
|
||||
.setOnLongClickIntent(pendingIntent)
|
||||
.build();
|
||||
|
||||
// Write to parcel
|
||||
Parcel parcel = Parcel.obtain();
|
||||
expectedCustomTile.writeToParcel(parcel, 0);
|
||||
|
||||
// Rewind
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
// Verify data when unraveling
|
||||
CustomTile fromParcel = CustomTile.CREATOR.createFromParcel(parcel);
|
||||
|
||||
assertNotNull(fromParcel.onLongClick);
|
||||
assertEquals(expectedCustomTile.onLongClick.getIntent().toString(),
|
||||
fromParcel.onLongClick.getIntent().toString());
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testCustomTileOnSettingsClickIntentUnravelFromParcel() {
|
||||
Intent intent = new Intent(mContext, DummySettings.class);
|
||||
|
Loading…
Reference in New Issue
Block a user