Skip to content

Commit

Permalink
Part 6 exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
migellal committed Jan 11, 2016
1 parent 6b2c6d5 commit 51fece9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .idea/dictionaries/micha.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 31 additions & 2 deletions app/src/main/java/pl/digitalzombielab/kenistoys/AppWidget.java
Expand Up @@ -5,22 +5,31 @@
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.os.Environment;
import android.widget.RemoteViews;
import android.widget.Toast;

import com.google.common.base.Charsets;
import com.google.common.io.Files;

import java.io.File;
import java.io.FilenameFilter;
import java.util.Random;

/**
* Implementation of App Widget functionality.
*/
public class AppWidget extends AppWidgetProvider {

private static String path = Environment.getExternalStorageDirectory() + "/Digital Zombie Lab/Kenis Toys/";

static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId, int[] appWidgetIds) {
// TODO load file
String number = String.valueOf(new Random().nextInt());
String content = getContent();
// Construct the RemoteViews object
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.app_widget);
views.setTextViewText(R.id.appwidget_text, number);
views.setTextViewText(R.id.appwidget_text, content);

// Instruct the widget manager to update the widget
Intent intent = new Intent(context, AppWidget.class);
Expand All @@ -40,5 +49,25 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a

}

private static String getContent()
{
try{
File file = new File(path);
String[] paths = file.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String filename) {
return filename.endsWith(".txt");
}
});
Random generator = new Random();
int i = generator.nextInt(paths.length);
return Files.toString(new File(path + paths[i]), Charsets.UTF_8);
}
catch (Exception e)
{
return e.toString();
}
}

}

Expand Up @@ -6,6 +6,7 @@
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
Expand All @@ -14,10 +15,10 @@
import android.widget.Button;
import android.widget.EditText;

public class CountdownActivity extends AppCompatActivity {
public class CountdownActivity extends AppCompatActivity implements CommonColors {

EditText title, body, value;
Button start;
private EditText title, body, value;
private Button start;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -26,6 +27,7 @@ protected void onCreate(Bundle savedInstanceState) {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setNaviBarColor();
title = (EditText) findViewById(R.id.notifyTitleET);
body = (EditText) findViewById(R.id.notifyBodyET);
value = (EditText) findViewById(R.id.notifyValueET);
Expand All @@ -49,4 +51,10 @@ private void createNotifi()


}

@Override
public void setNaviBarColor() {
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP)
getWindow().setNavigationBarColor(getApplicationContext().getColor(R.color.colorPrimaryDark));
}
}
Binary file modified app/src/main/res/drawable-nodpi/example_appwidget_preview.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/ico.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 51fece9

Please sign in to comment.