cmsdk: Add support for remote views in expanded styles
Change-Id: Ifa4e7f09df60c65fe476c5b9d332da0cb460e098
This commit is contained in:
parent
25daf555d2
commit
bd5230afe0
|
@ -25,6 +25,7 @@ import android.os.Parcel;
|
|||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
import cyanogenmod.os.Build;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -309,10 +310,16 @@ public class CustomTile implements Parcelable {
|
|||
*/
|
||||
public static final int LIST_STYLE = 1;
|
||||
|
||||
/**
|
||||
* Identifier for a remote view style expanded view
|
||||
*/
|
||||
public static final int REMOTE_STYLE = 2;
|
||||
|
||||
private ExpandedStyle() {
|
||||
styleId = NO_STYLE;
|
||||
}
|
||||
|
||||
private RemoteViews contentViews;
|
||||
private ExpandedItem[] expandedItems;
|
||||
private int styleId;
|
||||
|
||||
|
@ -333,6 +340,12 @@ public class CustomTile implements Parcelable {
|
|||
styleId = parcel.readInt();
|
||||
}
|
||||
|
||||
if (parcelableVersion >= Build.CM_VERSION_CODES.BOYSENBERRY) {
|
||||
if (parcel.readInt() != 0) {
|
||||
contentViews = RemoteViews.CREATOR.createFromParcel(parcel);
|
||||
}
|
||||
}
|
||||
|
||||
parcel.setDataPosition(startPosition + parcelableSize);
|
||||
}
|
||||
|
||||
|
@ -357,6 +370,13 @@ public class CustomTile implements Parcelable {
|
|||
items.toArray(expandedItems);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
protected void internalSetRemoteViews(RemoteViews remoteViews) {
|
||||
contentViews = remoteViews;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
|
@ -372,6 +392,14 @@ public class CustomTile implements Parcelable {
|
|||
return expandedItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the RemoteViews that have been set on this expanded style
|
||||
* @return RemoteViews
|
||||
*/
|
||||
public RemoteViews getContentViews() {
|
||||
return contentViews;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the style id associated with the {@link ExpandedStyle}
|
||||
* @return id for style
|
||||
|
@ -406,6 +434,14 @@ public class CustomTile implements Parcelable {
|
|||
}
|
||||
parcel.writeInt(styleId);
|
||||
|
||||
// ==== BOYSENBERRY ====
|
||||
if (contentViews != null) {
|
||||
parcel.writeInt(1);
|
||||
contentViews.writeToParcel(parcel, 0);
|
||||
} else {
|
||||
parcel.writeInt(0);
|
||||
}
|
||||
|
||||
// Go back and write size
|
||||
int parcelableSize = parcel.dataPosition() - startPosition;
|
||||
parcel.setDataPosition(sizePosition);
|
||||
|
@ -490,6 +526,26 @@ public class CustomTile implements Parcelable {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An instance of {@link ExpandedStyle} that shows a remote view in the remote process
|
||||
*/
|
||||
public static class RemoteExpandedStyle extends ExpandedStyle {
|
||||
/**
|
||||
* Constructs a RemoteExpandedStyle object with default values.
|
||||
*/
|
||||
public RemoteExpandedStyle() {
|
||||
internalStyleId(REMOTE_STYLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the RemoteViews for the {@link RemoteExpandedStyle}
|
||||
* @param remoteViews a remote view
|
||||
*/
|
||||
public void setRemoteViews(RemoteViews remoteViews) {
|
||||
internalSetRemoteViews(remoteViews);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A container object that is utilized by {@link ExpandedStyle} to show specific items in either
|
||||
* a PseudoGridView or a ListView via {@link GridExpandedStyle} and {@link ListExpandedStyle}
|
||||
|
|
|
@ -1,4 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2015 The CyanogenMod Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2015 The CyanogenMod Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_horizontal">
|
||||
|
||||
<ImageView
|
||||
android:src="@drawable/ic_whatshot_white_24dp"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:text="THIS IS A REMOTEVIEW"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/whats_hot_click"
|
||||
android:text="CLICK ME"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
|
@ -23,6 +23,7 @@ import android.graphics.BitmapFactory;
|
|||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
|
||||
import android.widget.RemoteViews;
|
||||
import cyanogenmod.app.CustomTile;
|
||||
import cyanogenmod.app.CMStatusBarManager;
|
||||
|
||||
|
@ -296,6 +297,36 @@ public class CMStatusBarTest extends TestActivity {
|
|||
CMStatusBarManager.getInstance(CMStatusBarTest.this)
|
||||
.publishTile(CUSTOM_TILE_SETTINGS_ID, customTile);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
new Test("test publish tile with remote view") {
|
||||
public void run() {
|
||||
RemoteViews contentView = new RemoteViews(getPackageName(),
|
||||
R.layout.remote_view);
|
||||
|
||||
Intent daneshIntent = new Intent(Intent.ACTION_VIEW)
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.setData(Uri.parse("http://www.reddit.com/r/daneshsayings"));
|
||||
PendingIntent intent = PendingIntent.getActivity(CMStatusBarTest.this, 0,
|
||||
daneshIntent, 0);
|
||||
contentView.setOnClickPendingIntent(R.id.whats_hot_click, intent);
|
||||
|
||||
CustomTile.RemoteExpandedStyle remoteExpandedStyle =
|
||||
new CustomTile.RemoteExpandedStyle();
|
||||
remoteExpandedStyle.setRemoteViews(contentView);
|
||||
|
||||
CustomTile customTile = new CustomTile.Builder(CMStatusBarTest.this)
|
||||
.setLabel("Test Expanded Remote Style From SDK")
|
||||
.setIcon(R.drawable.ic_launcher)
|
||||
.setExpandedStyle(remoteExpandedStyle)
|
||||
.setOnSettingsClickIntent(new Intent(CMStatusBarTest.this,
|
||||
DummySettings.class)
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
.setContentDescription("Content description")
|
||||
.build();
|
||||
CMStatusBarManager.getInstance(CMStatusBarTest.this)
|
||||
.publishTile(CUSTOM_TILE_SETTINGS_ID, customTile);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import android.test.AndroidTestCase;
|
|||
|
||||
import android.test.suitebuilder.annotation.MediumTest;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.widget.RemoteViews;
|
||||
import cyanogenmod.app.CustomTile;
|
||||
|
||||
import org.cyanogenmod.tests.R;
|
||||
|
@ -282,4 +283,32 @@ public class CustomTileTest extends AndroidTestCase {
|
|||
assertEquals(itemExpected.itemSummary, itemReal.itemSummary);
|
||||
}
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testCustomTileExpandedRemoteStyleUnravelFromParcel() {
|
||||
RemoteViews contentView = new RemoteViews(mContext.getPackageName(), R.layout.remote_view);
|
||||
|
||||
CustomTile.RemoteExpandedStyle remoteExpandedStyle =
|
||||
new CustomTile.RemoteExpandedStyle();
|
||||
remoteExpandedStyle.setRemoteViews(contentView);
|
||||
|
||||
CustomTile expectedCustomTile = new CustomTile.Builder(mContext)
|
||||
.setExpandedStyle(remoteExpandedStyle)
|
||||
.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.expandedStyle);
|
||||
assertEquals(expectedCustomTile.expandedStyle.getStyle(),
|
||||
fromParcel.expandedStyle.getStyle());
|
||||
assertNotNull(fromParcel.expandedStyle.getContentViews());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue