Skip to content

Commit 057aa73

Browse files
author
Yoav Sternberg
committed
Dark, transparent ui for button, async intent creator
1 parent 5b79e14 commit 057aa73

11 files changed

Lines changed: 118 additions & 29 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:color="@color/back_button_color_dark_pressed">
4+
<item android:drawable="@color/back_button_color_dark_normal"/>
5+
</ripple>
4.54 KB
Loading
3.22 KB
Loading
3.22 KB
Loading
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:state_pressed="true" android:drawable="@color/back_button_color_dark_pressed" />
4+
<item android:drawable="@color/back_button_color_dark_normal" />
5+
</selector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:state_pressed="true" android:drawable="@color/back_button_color_semi_transparent_pressed" />
4+
<item android:drawable="@color/back_button_color_semi_transparent_normal" />
5+
</selector>

QCircle-Design-Template/res/layout/qcircle_empty.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
android:layout_width="match_parent"
2121
android:layout_height="match_parent"
2222
android:layout_centerHorizontal="true"
23-
android:gravity="center_vertical"
24-
>
23+
android:gravity="center_vertical">
2524

2625
<RelativeLayout
2726
android:id="@+id/main"
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<color name="back_button_color_normal">#DDDDDD</color>
3+
<color name="back_button_color_normal">#E1E1E1</color>
44
<color name="back_button_color_pressed">#BDBDBD</color>
5+
<color name="back_button_color_dark_normal">#607D8B</color>
6+
<color name="back_button_color_dark_pressed">#78909C</color>
7+
<color name="back_button_color_semi_transparent_normal">#30000000</color>
8+
<color name="back_button_color_semi_transparent_pressed">#60000000</color>
59
</resources>

QCircle-Design-Template/src/com/lge/qcircle/template/QCircleBackButton.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
*/
1717
public final class QCircleBackButton {
1818
private final String TAG = "QCircleBackButton";
19-
19+
private OnClickListener mListener;
2020
private ImageView mBtnContent = null;
2121
private Context mContext = null;
22+
private boolean isDark = false;
2223

2324
/**
2425
* creates a back button.
@@ -27,7 +28,19 @@ public final class QCircleBackButton {
2728
* <b>If it is null, you might get errors when you use method of this class.</b>
2829
*/
2930
public QCircleBackButton(Context context) {
31+
this(context, null);
32+
}
33+
34+
/**
35+
* creates a back button.
36+
*
37+
* @param context {@code Activity} which has a circle view.<br>
38+
* <b>If it is null, you might get errors when you use method of this class.</b>
39+
* @param listener Listener on click
40+
*/
41+
public QCircleBackButton(Context context, OnClickListener listener) {
3042
mContext = context;
43+
mListener = listener;
3144
if (!setButton())
3245
Log.d(TAG, "Cannot create a button. Context is null.");
3346
}
@@ -44,12 +57,12 @@ private boolean setButton() {
4457
mBtnContent = new ImageView(mContext);
4558
// set attributes
4659
mBtnContent.setId(R.id.backButton);
47-
mBtnContent.setImageResource(R.drawable.backover);
48-
mBtnContent.setBackgroundResource(R.drawable.back_button_background);
60+
setTheme();
4961
mBtnContent.setScaleType(ScaleType.CENTER);
5062
mBtnContent.setOnClickListener(new OnClickListener() {
5163
@Override
5264
public void onClick(View v) {
65+
if (mListener != null) mListener.onClick(v);
5366
if (mContext != null) {
5467
try {
5568
((Activity) mContext).finish();
@@ -64,6 +77,16 @@ public void onClick(View v) {
6477
return result;
6578
}
6679

80+
81+
private void setTheme() {
82+
mBtnContent.setImageResource(isDark ? R.drawable.backover_dark : R.drawable.backover);
83+
mBtnContent.setBackgroundResource(isDark ? R.drawable.back_button_background_dark : R.drawable.back_button_background);
84+
}
85+
86+
public void isDark(boolean isDark) {
87+
this.isDark = isDark;
88+
setTheme();
89+
}
6790
/**
6891
* gets the view of the button.
6992
*
@@ -78,7 +101,7 @@ public View getView() {
78101
*
79102
* @return ID of the button view
80103
*/
81-
public int getId() {
104+
public static int getId() {
82105
return R.id.backButton;
83106
}
84107

@@ -87,6 +110,6 @@ public int getId() {
87110
*/
88111
public void setBackgroundTransparent() {
89112
if (mBtnContent != null)
90-
mBtnContent.setBackgroundColor(Color.TRANSPARENT);
113+
mBtnContent.setBackgroundResource(R.drawable.back_button_background_semi_transparent);
91114
}
92115
}

QCircle-Design-Template/src/com/lge/qcircle/template/QCircleTemplate.java

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lge.qcircle.template;
22

33
import android.app.Activity;
4+
import android.content.ActivityNotFoundException;
45
import android.content.BroadcastReceiver;
56
import android.content.Context;
67
import android.content.Intent;
@@ -56,6 +57,7 @@ public class QCircleTemplate {
5657
protected Context mContext = null;
5758
protected BroadcastReceiver mReceiver = null;
5859
protected Intent mFullscreenIntent = null;
60+
protected IntentCreatorAsync mAsyncCreator = null;
5961

6062
// Views
6163
protected TemplateType mLayoutType = TemplateType.CIRCLE_EMPTY;
@@ -99,7 +101,7 @@ public QCircleTemplate(Context context) {
99101
*/
100102
public QCircleTemplate(Context context, TemplateType type) {
101103
mContext = context;
102-
registerIntentReceiver(); // register cover events
104+
registerIntentReceiver();
103105
if (type == null)
104106
type = TemplateType.CIRCLE_EMPTY;
105107
setTemplateType(type); // set layout style
@@ -135,6 +137,17 @@ public void setFullscreenIntent(Intent intent) {
135137
Log.w(TAG, "The given intent is null");
136138
}
137139
mFullscreenIntent = intent;
140+
mAsyncCreator = null;
141+
}
142+
143+
/**
144+
* sets the intent running in fullscreen when the cover is opened.
145+
*
146+
* @param creatorAsync will be called only when need the intent.
147+
*/
148+
public void setFullscreenIntent(IntentCreatorAsync creatorAsync) {
149+
mFullscreenIntent = null;
150+
mAsyncCreator = creatorAsync;
138151
}
139152

140153
/**
@@ -144,6 +157,7 @@ public void setFullscreenIntent(Intent intent) {
144157
* @return root view of the layout.
145158
*/
146159
public View getView() {
160+
setQuickCircleWindowParam();
147161
return mRootLayout;
148162
}
149163

@@ -277,10 +291,25 @@ public void setTitle(View titleView, float heightRatio) {
277291
* has one.<br>
278292
* Note that this method does not create a button when the button already exists.
279293
*/
280-
public void setBackbutton() {
294+
public void setBackButton() {
295+
setBackButton(null);
296+
}
297+
298+
/**
299+
* sets a back button with callback.
300+
* <p>
301+
* It creates a back button on the bottom of the layout.
302+
* <p>
303+
* You do not need to implement an {@code onClickListener} for the button, because it already
304+
* has one.<br>
305+
* Note that this method does not create a button when the button already exists.
306+
* @param onClickListener Callback for back button.
307+
* <b>should be used for closing objects, like camera</b>
308+
*/
309+
public void setBackButton(View.OnClickListener onClickListener) {
281310
if (mBackButton == null) {
282311
if (mContext != null)
283-
mBackButton = new QCircleBackButton(mContext);
312+
mBackButton = new QCircleBackButton(mContext, onClickListener);
284313
else {
285314
Log.e(TAG, "Cannot create the back button: context is null");
286315
return;
@@ -289,6 +318,16 @@ public void setBackbutton() {
289318
}
290319
}
291320

321+
/**
322+
* Set the theme to the back button. Default is light.
323+
* @param isDark Is dark theme
324+
*/
325+
public void setBackButtonTheme(boolean isDark) {
326+
if (mBackButton != null) {
327+
mBackButton.isDark(isDark);
328+
}
329+
}
330+
292331
/**
293332
* gets a layout with the given id.
294333
* <p>
@@ -303,15 +342,6 @@ public RelativeLayout getLayoutById(int id) {
303342
RelativeLayout result = null;
304343
if (mContent != null && id > 0) {
305344
result = (RelativeLayout) mContent.findViewById(id);
306-
// if (result == null && mContent.findViewById(R.id.content_top) != null) {
307-
// result = (RelativeLayout)mContent.findViewById(R.id.content_top).findViewById(id);
308-
// } else if (result == null && mContentLayout != null) {
309-
// result = (RelativeLayout)mContentLayout.findViewById(id);
310-
// }
311-
// for R.id.content
312-
// if( result == null && ( mLayoutType == TemplateType.CIRCLE_COMPLEX || mLayoutType ==
313-
// TemplateType.CIRCLE_EMPTY) )
314-
// return mContent;
315345
}
316346
return result;
317347
}
@@ -483,7 +513,7 @@ private void addTitleView(QCircleTitle titleView, float heightRatio) {
483513
/**
484514
* adds a button view to the layout.
485515
* <p>
486-
* It is called by {@link QCircleTemplate#setBackbutton()} to adjust the circle layout. The
516+
* It is called by {@link QCircleTemplate#setBackButton()} to adjust the circle layout. The
487517
* button view is added on the bottom of the layout and the content window will be on the top of
488518
* the button view.
489519
*
@@ -639,15 +669,21 @@ public void onReceive(Context context, Intent intent) {
639669
// Gets the current state of the cover
640670
int quickCoverState = intent.getIntExtra(EXTRA_ACCESSORY_COVER_STATE,
641671
EXTRA_ACCESSORY_COVER_OPENED);
642-
// Log.d(TAG, "quickCoverState= " + quickCoverState);
643672
if (quickCoverState == EXTRA_ACCESSORY_COVER_CLOSED) { // closed
644-
// } else
645-
// intenta.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
646-
setQuickCircleWindowParam();
673+
//setQuickCircleWindowParam();
647674
} else if (quickCoverState == EXTRA_ACCESSORY_COVER_OPENED) { // opened
648675
if (mFullscreenIntent != null && mContext != null) {
649-
mContext.unregisterReceiver(this);
650676
mContext.startActivity(mFullscreenIntent);
677+
} else if (mContent != null && mAsyncCreator != null) {
678+
Intent launching = mAsyncCreator.getIntent();
679+
if (launching != null) {
680+
try {
681+
mContext.startActivity(launching);
682+
} catch (ActivityNotFoundException e) {
683+
// Package does not exist, ignore.
684+
e.printStackTrace();
685+
}
686+
}
651687
}
652688
if (mContext instanceof Activity) {
653689
((Activity) mContext).finish();
@@ -662,6 +698,14 @@ public void onReceive(Context context, Intent intent) {
662698
mContext.registerReceiver(mReceiver, filter);
663699
}
664700

701+
public void unregisterReceiver() {
702+
try {
703+
mContext.unregisterReceiver(mReceiver);
704+
} catch (Exception ignored) {
705+
// Receiver not registered
706+
}
707+
}
708+
665709
/**
666710
* makes the circle shown even if the screen is locked.
667711
*/
@@ -712,7 +756,7 @@ protected boolean setLayoutById(int id, View view) {
712756
*/
713757
protected void loadCustomTemplate(int templateId) {
714758
if (mContext != null && templateId > 0) {
715-
View layoutView = (View) ((Activity) mContext).getLayoutInflater().inflate(templateId,
759+
View layoutView = ((Activity) mContext).getLayoutInflater().inflate(templateId,
716760
null);
717761
if (layoutView == null)
718762
Log.w(TAG, "Cannot set the custom layout: " + templateId);
@@ -724,4 +768,8 @@ protected void loadCustomTemplate(int templateId) {
724768
Log.w(TAG, "Cannot set the custom layout. Context is null");
725769
}
726770
}
727-
}
771+
772+
public static interface IntentCreatorAsync {
773+
Intent getIntent();
774+
}
775+
}

0 commit comments

Comments
 (0)