Skip to content

Commit

Permalink
Toast replaced by bg change
Browse files Browse the repository at this point in the history
  • Loading branch information
alseambusher committed Oct 27, 2015
1 parent 97a28fc commit 7ce9f38
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/build
*.swp
*~
37 changes: 23 additions & 14 deletions src/main/java/com/alse/adbtoggle/AdbToggle.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.alse.adbtoggle;

import android.app.Activity;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.text.Layout;
import android.widget.RemoteViews;
import android.widget.Toast;

Expand Down Expand Up @@ -51,37 +54,43 @@ public void onDisabled(Context context) {
// Enter relevant functionality for when the last widget is disabled
}

private boolean isAdbOn(Context context){
if (Settings.Global.getInt(context.getContentResolver(), Settings.Global.ADB_ENABLED, 0) == 1)
return true;
return false;
}
private void toggleAdb(Context context){
int adb = isAdbOn(context) ? 0 : 1;
Settings.Global.putInt(context.getContentResolver(),
Settings.Global.ADB_ENABLED, adb);
}

@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if (ACTION_UPDATE_CLICK.equals(intent.getAction())){
int adb = Settings.Global.getInt(context.getContentResolver(),
Settings.Global.ADB_ENABLED, 0);
// toggle the USB debugging setting
adb = adb == 0 ? 1 : 0;
Settings.Global.putInt(context.getContentResolver(),
Settings.Global.ADB_ENABLED, adb);
if (adb == 1)
Toast.makeText(context, "Enabled ADB", Toast.LENGTH_SHORT).show();
else
Toast.makeText(context, "Disabled ADB", Toast.LENGTH_SHORT).show();

toggleAdb(context);
ComponentName cn = new ComponentName(context, AdbToggle.class);
for (int appWidgetID : AppWidgetManager.getInstance(context).getAppWidgetIds(cn)){
updateAppWidget(context, AppWidgetManager.getInstance(context), appWidgetID);
}
}
}

private void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId) {

CharSequence widgetText = context.getString(R.string.appwidget_text);
// Construct the RemoteViews object
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.adb_toggle);
RemoteViews views = new RemoteViews(context.getPackageName(), isAdbOn(context) ? R.layout.adb_toggle : R.layout.adb_toggle_off);
views.setTextViewText(R.id.appwidget_text, widgetText);
views.setTextViewText(R.id.appwidget_state, isAdbOn(context) ? "ON" : "OFF");

Intent intent = new Intent(context, getClass());
intent.setAction(ACTION_UPDATE_CLICK);
PendingIntent pending = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

views.setOnClickPendingIntent(R.id.appwidget_text, pending);

views.setOnClickPendingIntent(R.id.appwidget_layout, pending);
// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
Expand Down
Binary file not shown.
Binary file added src/main/res/drawable-nodpi/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 29 additions & 10 deletions src/main/res/layout/adb_toggle.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:padding="@dimen/widget_margin" android:background="#09C">

<TextView android:id="@+id/appwidget_text" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_centerHorizontal="true"
android:layout_centerVertical="true" android:text="ADB"
android:textColor="#ffffff" android:textSize="24sp"
android:layout_margin="8dp" android:contentDescription="@string/appwidget_text"
android:background="#09C"
android:textStyle="bold"
android:gravity="center" />
android:padding="@dimen/widget_margin">

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:id="@+id/appwidget_layout"
android:background="@color/on"
>

<TextView android:id="@+id/appwidget_text" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_centerHorizontal="true"
android:layout_centerVertical="true" android:text="ADB"
android:textColor="#ffffff" android:textSize="24sp"
android:layout_margin="0dp" android:contentDescription="@string/appwidget_text"
android:background="#09C"
android:textStyle="bold"
android:gravity="center" />

<TextView android:id="@+id/appwidget_state" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_centerHorizontal="true"
android:layout_centerVertical="true" android:text="ON"
android:textColor="#ffffff" android:textSize="24sp"
android:layout_margin="0dp" android:contentDescription="@string/appwidget_text"
android:background="#09C"
android:textStyle="bold"
android:gravity="center" />
</LinearLayout>

</RelativeLayout>
31 changes: 31 additions & 0 deletions src/main/res/layout/adb_toggle_off.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:padding="@dimen/widget_margin">

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:id="@+id/appwidget_layout"
android:background="@color/off"
>

<TextView android:id="@+id/appwidget_text" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_centerHorizontal="true"
android:layout_centerVertical="true" android:text="ADB"
android:textColor="#ffffff" android:textSize="24sp"
android:layout_margin="0dp" android:contentDescription="@string/appwidget_text"
android:textStyle="bold"
android:gravity="center" />

<TextView android:id="@+id/appwidget_state" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_centerHorizontal="true"
android:layout_centerVertical="true" android:text="ON"
android:textColor="#ffffff" android:textSize="24sp"
android:layout_margin="0dp" android:contentDescription="@string/appwidget_text"
android:textStyle="bold"
android:gravity="center" />
</LinearLayout>

</RelativeLayout>
Binary file modified src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
<string name="app_name">ADB Toggle</string>
<string name="appwidget_text">ADB</string>
<string name="add_widget">Add widget</string>
<color name="on">#09C</color>
<color name="off">#F44336</color>
</resources>
2 changes: 1 addition & 1 deletion src/main/res/xml/adb_toggle_info.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="40dp" android:minHeight="40dp" android:updatePeriodMillis="86400000"
android:previewImage="@drawable/example_appwidget_preview"
android:previewImage="@drawable/preview"
android:initialLayout="@layout/adb_toggle" android:widgetCategory="home_screen"
android:initialKeyguardLayout="@layout/adb_toggle"></appwidget-provider>

0 comments on commit 7ce9f38

Please sign in to comment.