change the package name

This commit is contained in:
tibbi
2016-02-25 22:11:03 +01:00
parent 9eefa472fc
commit b8642927a1
9 changed files with 12 additions and 12 deletions

View File

@ -0,0 +1,8 @@
package com.simplemobiletools.notes;
public class Constants {
public static final String PREFS = "prefs";
public static final String TEXT = "text";
public static final String WIDGET_BG_COLOR = "widget_bg_color";
public static final String WIDGET_TEXT_COLOR = "widget_text_color";
}

View File

@ -0,0 +1,77 @@
package com.simplemobiletools.notes;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.Toast;
import butterknife.Bind;
import butterknife.ButterKnife;
public class MainActivity extends AppCompatActivity {
private SharedPreferences prefs;
@Bind(R.id.notes_view) EditText notesView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
prefs = getSharedPreferences(Constants.PREFS, Context.MODE_PRIVATE);
final String text = prefs.getString(Constants.TEXT, "");
notesView.setText(text);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.save:
saveText();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void saveText() {
final String text = notesView.getText().toString().trim();
prefs.edit().putString(Constants.TEXT, text).apply();
Toast.makeText(this, "Text saved", Toast.LENGTH_SHORT).show();
hideKeyboard();
updateWidget();
}
private void hideKeyboard() {
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(notesView.getWindowToken(), 0);
}
private void updateWidget() {
final Context context = getApplicationContext();
final AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);
int[] ids = widgetManager.getAppWidgetIds(new ComponentName(context, MyWidgetProvider.class));
final Intent intent = new Intent(this, MyWidgetProvider.class);
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
sendBroadcast(intent);
}
}

View File

@ -0,0 +1,170 @@
package com.simplemobiletools.notes;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.RemoteViews;
import android.widget.SeekBar;
import android.widget.TextView;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import yuku.ambilwarna.AmbilWarnaDialog;
public class MyWidgetConfigure extends AppCompatActivity {
@Bind(R.id.config_bg_color) View bgColorPicker;
@Bind(R.id.config_bg_seekbar) SeekBar bgSeekBar;
@Bind(R.id.config_text_color) View textColorPicker;
@Bind(R.id.notes_view) TextView notesView;
@Bind(R.id.config_save) Button saveBtn;
private int widgetId;
private int bgColor;
private int bgColorWithoutTransparency;
private float bgAlpha;
private int textColor;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setResult(RESULT_CANCELED);
setContentView(R.layout.widget_config);
ButterKnife.bind(this);
initVariables();
final Intent intent = getIntent();
final Bundle extras = intent.getExtras();
if (extras != null)
widgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
if (widgetId == AppWidgetManager.INVALID_APPWIDGET_ID)
finish();
}
private void initVariables() {
final SharedPreferences prefs = getSharedPreferences(Constants.PREFS, Context.MODE_PRIVATE);
bgColor = prefs.getInt(Constants.WIDGET_BG_COLOR, 0);
if (bgColor == 0) {
bgColor = Color.BLACK;
bgAlpha = .5f;
} else {
bgAlpha = Color.alpha(bgColor) / (float) 255;
}
bgColorWithoutTransparency = Color.rgb(Color.red(bgColor), Color.green(bgColor), Color.blue(bgColor));
bgSeekBar.setOnSeekBarChangeListener(bgSeekbarChangeListener);
bgSeekBar.setProgress((int) (bgAlpha * 100));
updateBackgroundColor();
textColor = prefs.getInt(Constants.WIDGET_TEXT_COLOR, Color.WHITE);
updateTextColor();
}
@OnClick(R.id.config_save)
public void saveConfig() {
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
final RemoteViews views = new RemoteViews(getPackageName(), R.layout.activity_main);
views.setInt(R.id.notes_view, "setBackgroundColor", bgColor);
appWidgetManager.updateAppWidget(widgetId, views);
storeWidgetBackground();
requestWidgetUpdate();
final Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
setResult(RESULT_OK, resultValue);
finish();
}
private void storeWidgetBackground() {
final SharedPreferences prefs = getSharedPreferences(Constants.PREFS, Context.MODE_PRIVATE);
prefs.edit().putInt(Constants.WIDGET_BG_COLOR, bgColor).apply();
prefs.edit().putInt(Constants.WIDGET_TEXT_COLOR, textColor).apply();
}
private void requestWidgetUpdate() {
final Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null, this, MyWidgetProvider.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[]{widgetId});
sendBroadcast(intent);
}
private void updateBackgroundColor() {
bgColor = adjustAlpha(bgColorWithoutTransparency, bgAlpha);
notesView.setBackgroundColor(bgColor);
bgColorPicker.setBackgroundColor(bgColor);
saveBtn.setBackgroundColor(bgColor);
}
private void updateTextColor() {
textColorPicker.setBackgroundColor(textColor);
saveBtn.setTextColor(textColor);
notesView.setTextColor(textColor);
}
@OnClick(R.id.config_bg_color)
public void pickBackgroundColor() {
AmbilWarnaDialog dialog = new AmbilWarnaDialog(this, bgColorWithoutTransparency, new AmbilWarnaDialog.OnAmbilWarnaListener() {
@Override
public void onCancel(AmbilWarnaDialog dialog) {
}
@Override
public void onOk(AmbilWarnaDialog dialog, int color) {
bgColorWithoutTransparency = color;
updateBackgroundColor();
}
});
dialog.show();
}
@OnClick(R.id.config_text_color)
public void pickTextColor() {
AmbilWarnaDialog dialog = new AmbilWarnaDialog(this, textColor, new AmbilWarnaDialog.OnAmbilWarnaListener() {
@Override
public void onCancel(AmbilWarnaDialog dialog) {
}
@Override
public void onOk(AmbilWarnaDialog dialog, int color) {
textColor = color;
updateTextColor();
}
});
dialog.show();
}
private SeekBar.OnSeekBarChangeListener bgSeekbarChangeListener = new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
bgAlpha = (float) progress / (float) 100;
updateBackgroundColor();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
};
private int adjustAlpha(int color, float factor) {
final int alpha = Math.round(Color.alpha(color) * factor);
final int red = Color.red(color);
final int green = Color.green(color);
final int blue = Color.blue(color);
return Color.argb(alpha, red, green, blue);
}
}

View File

@ -0,0 +1,34 @@
package com.simplemobiletools.notes;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.widget.RemoteViews;
public class MyWidgetProvider extends AppWidgetProvider {
private static SharedPreferences prefs;
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
prefs = context.getSharedPreferences(Constants.PREFS, Context.MODE_PRIVATE);
final RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
final int defaultColor = context.getResources().getColor(R.color.dark_grey);
final int newBgColor = prefs.getInt(Constants.WIDGET_BG_COLOR, defaultColor);
final int newTextColor = prefs.getInt(Constants.WIDGET_TEXT_COLOR, Color.WHITE);
remoteViews.setInt(R.id.notes_view, "setBackgroundColor", newBgColor);
remoteViews.setInt(R.id.notes_view, "setTextColor", newTextColor);
for (int widgetId : appWidgetIds) {
updateWidget(appWidgetManager, widgetId, remoteViews);
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
private void updateWidget(AppWidgetManager widgetManager, int widgetId, RemoteViews remoteViews) {
final String text = prefs.getString(Constants.TEXT, "");
remoteViews.setTextViewText(R.id.notes_view, text);
widgetManager.updateAppWidget(widgetId, remoteViews);
}
}