Commit 02059f9b authored by Giacomo Lavermicocca's avatar Giacomo Lavermicocca Committed by Pietro Saccardi

Widget,activity and others stuff completed...

parent 6aed6939
......@@ -4,6 +4,7 @@
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:allowBackup="true"
......@@ -37,8 +38,8 @@
</receiver>
<activity
android:name=".Main1Activity"
android:label="@string/title_activity_main1"
android:name=".MainActivity"
android:label="Titolo..."
android:theme="@style/AppTheme.NoActionBar"
android:exported="true">
<intent-filter>
......
package it.giacomo.sesamo;
import android.appwidget.AppWidgetManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.telephony.SmsManager;
import android.telephony.SubscriptionInfo;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import java.util.List;
import it.giacomo.sesamo.managers.SendSms;
public class Main1Activity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main1);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
//setContentView(R.layout.activity_main1);
//Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//setSupportActionBar(toolbar);
String val = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("numero_sms", "");
Toast.makeText(getApplicationContext(), val, Toast.LENGTH_LONG).show();
//SmsManager.getSmsManagerForSubscriptionId(subscriptionId).sendTextMessage(destinationAddress, scAddress, text, sentIntent, deliveryIntent);
SendSms sms = new SendSms();
sms.Do(2, "", null, "OPEN_2", null, null);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
int mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
Log.e("TAGG", mAppWidgetId+"");
//Snackbar.make(view, ""+mAppWidgetId, Snackbar.LENGTH_LONG).setAction("Action", null).show();
}
finish();
}
}
......@@ -10,6 +10,8 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity;
......@@ -17,11 +19,15 @@ import android.telephony.SmsManager;
import android.telephony.SubscriptionInfo;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.google.firebase.messaging.FirebaseMessaging;
import org.w3c.dom.Text;
import java.util.List;
import it.giacomo.sesamo.beans.SimInfo;
......@@ -29,81 +35,71 @@ import it.giacomo.sesamo.managers.SendSms;
public class MainActivity extends AppCompatActivity {
private TextView mTextMessage;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
mTextMessage.setText(R.string.title_home);
return true;
case R.id.navigation_dashboard:
// AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getApplicationContext());
// RemoteViews views = new RemoteViews(getApplicationContext().getPackageName(), R.layout.activity_main_widget);
// appWidgetManager.updateAppWidget(mAppWidgetId, views);
mTextMessage.setText(R.string.title_dashboard);
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
finish();
return true;
case R.id.navigation_notifications:
mTextMessage.setText(R.string.title_notifications);
return true;
}
return false;
}
};
int mAppWidgetId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
Log.e("TAGG", mAppWidgetId+"");
}
Button btnEsci = (Button) findViewById(R.id.btnEsci);
Bundle b = getIntent().getExtras();
int value = -1; // or other values
if(b != null)
value = b.getInt("OPEN");
Toast.makeText(getApplicationContext(), "QUI", Toast.LENGTH_LONG).show();
btnEsci.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MainActivity.this.finish();
}
});
// Toast.makeText(getApplicationContext(), val, Toast.LENGTH_LONG).show();
//
// Intent intent = getIntent();
// Bundle extras = intent.getExtras();
// if (extras != null) {
// mAppWidgetId = extras.getInt(
// AppWidgetManager.EXTRA_APPWIDGET_ID,
// AppWidgetManager.INVALID_APPWIDGET_ID);
// Log.e("TAGG", mAppWidgetId+"");
// }
FirebaseMessaging.getInstance().subscribeToTopic("OPEN");
mTextMessage = (TextView) findViewById(R.id.message);
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
String value = "";
if(getIntent().getExtras() != null) {
value = getIntent().getExtras().getString("OPEN");
List<SimInfo> s = SendSms.getSIMInfo(getApplicationContext());
SendSms sms = new SendSms();
Log.e("TAG", ""+s.size());
String prefContatto = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("prefContatto", "");
SendSms sms = new SendSms();
int prefOperatore = Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("prefOperatore", "0"));
List<SubscriptionInfo> t = sms.getSubscriptionList(getApplicationContext());
sms.Do(prefOperatore, prefContatto, null, value, null, null);
// SharedPreferences prefs = getSharedPreferences(MY_PREFERENCES, Context.MODE_PRIVATE);
// String textData = prefs.getString(TEXT_DATA_KEY, "No Preferences!");
Toast.makeText(getApplicationContext(), value, Toast.LENGTH_SHORT).show();
sms.Do(2, "", null, "OPEN_2", null, null);
TextView mTextField = (TextView) findViewById(R.id.timer);
CountD(mTextField);
}
}
private void CountD(final TextView mTextField)
{
new CountDownTimer(10000, 1000) {
public void onTick(long millisUntilFinished) {
mTextField.setText(""+ millisUntilFinished / 1000);
}
public void onFinish() {
mTextField.setText("Ciao!");
}
}.start();
}
private void sendSMS(final String phoneNumber, final String message) {
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
......
......@@ -21,55 +21,43 @@ public class MainActivityWidget extends AppWidgetProvider {
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for(int i=0; i<appWidgetIds.length; i++){
int currentWidgetId = appWidgetIds[i];
String url = "it.giacomo.sesamo.MainActivity";
Intent intent = new Intent(context, SettingsActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//intent.setData(Uri.parse(url));
PendingIntent pending = PendingIntent.getActivity(context, 0,intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.activity_main_widget);
views.setOnClickPendingIntent(R.id.btn_entro, pending);
appWidgetManager.updateAppWidget(currentWidgetId, views);
Toast.makeText(context, "widget added", Toast.LENGTH_SHORT).show();
views.setOnClickPendingIntent(R.id.btn_esci, makePIntent(context, 0, "OPEN_0"));
views.setOnClickPendingIntent(R.id.btn_garage, makePIntent(context, 1, "OPEN_1"));
views.setOnClickPendingIntent(R.id.btn_portone, makePIntent(context, 2, "OPEN_2"));
views.setOnClickPendingIntent(R.id.btn_entro, makePIntent(context, 3, "OPEN_3"));
// int currentWidgetId = appWidgetIds[i];
//
// RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.activity_main);
//
// PendingIntent pending = makePIntent(context, 0);
// views.setOnClickPendingIntent(R.id.btn_esci, pending);
// appWidgetManager.updateAppWidget(currentWidgetId, views);
//
// Intent iSetting = new Intent(context, MainActivity.class);
// PendingIntent piSetting = PendingIntent.getActivity(context, 0, iSetting, 0);
// views.setOnClickPendingIntent(R.id.btn_garage, piSetting);
//
// pending = makePIntent(context, 1);
// views.setOnClickPendingIntent(R.id.btn_entro, pending);
// appWidgetManager.updateAppWidget(currentWidgetId,views);
//
// pending = makePIntent(context, 2);
// views.setOnClickPendingIntent(R.id.btn_garage, pending);
// appWidgetManager.updateAppWidget(currentWidgetId,views);
//
// pending = makePIntent(context, 3);
// views.setOnClickPendingIntent(R.id.btn_portone, pending);
// appWidgetManager.updateAppWidget(currentWidgetId,views);
appWidgetManager.updateAppWidget(currentWidgetId, views);
Toast.makeText(context, "widget added", Toast.LENGTH_SHORT).show();
}
}
private PendingIntent makePIntent(Context context, int value)
private PendingIntent makePIntent(Context context, int value, String val)
{
Intent intent = new Intent(context, MainActivity.class);
Bundle b = new Bundle();
b.putInt("OPEN", value); //Your id
intent.putExtras(b); //Put your id to your next Intent
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return PendingIntent.getActivity(context, 2, intent, 0);
Intent intent = new Intent(context, MainActivityWidget.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(val);
intent.putExtra("OPEN", val);
//PendingIntent pending = PendingIntent.getActivity(context, 0,intent, 0);
return PendingIntent.getBroadcast(context, 0, intent, 0);
//return pending;
}
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if(intent.getAction().contains("OPEN")) {
Intent nextIntent = new Intent(context, MainActivity.class);
nextIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
nextIntent.putExtra("OPEN", intent.getAction());
context.startActivity(nextIntent);
Toast.makeText(context, intent.getAction(), Toast.LENGTH_SHORT).show();
}
}
}
\ No newline at end of file
......@@ -2,15 +2,27 @@ package it.giacomo.sesamo;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.provider.ContactsContract;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
import it.giacomo.sesamo.beans.SimInfo;
import it.giacomo.sesamo.managers.SendSms;
public class SettingsActivity extends PreferenceActivity implements Preference.OnPreferenceChangeListener{
public class SettingsActivity extends PreferenceActivity implements Preference.OnPreferenceChangeListener {
public static class MyPreferenceFragment extends PreferenceFragment
{
@Override
......@@ -20,7 +32,8 @@ public class SettingsActivity extends PreferenceActivity implements Preference.O
try{
addPreferencesFromResource(R.xml.settings);
final SettingsActivity m = new SettingsActivity();
m.bindPreferenceSummaryToValue(findPreference("numero_sms"));
m.setListPrefContatti(getActivity().getApplicationContext(), (ListPreference) findPreference("prefContatto"));
m.setListPrefOperatori(getActivity().getApplicationContext(), (ListPreference) findPreference("prefOperatore"));
}catch(Exception exp){
exp.toString();
}
......@@ -29,6 +42,8 @@ public class SettingsActivity extends PreferenceActivity implements Preference.O
@Override
public void onBackPressed() {
//Esco dall'applicazione!!! Nel modo giusto però... sono in un widget
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
......@@ -37,27 +52,70 @@ public class SettingsActivity extends PreferenceActivity implements Preference.O
}
int mAppWidgetId;
private void bindPreferenceSummaryToValue(Preference preference) {
public void setListPrefOperatori(Context context, ListPreference lp) {
// Set the listener to watch for value changes.
lp.setOnPreferenceChangeListener(this);
// Trigger the listener immediately with the preference's
// current value.
onPreferenceChange(lp, PreferenceManager.getDefaultSharedPreferences(lp.getContext()).getString(lp.getKey(), ""));
List<SimInfo> s = SendSms.getSIMInfo(context);
SortedMap<String, String> hMap = new TreeMap<>();
for (SimInfo item: s) {
hMap.put(item.getDisplay_name(), ""+item.getId_());
}
CharSequence[] entries = hMap.keySet().toArray(new CharSequence[]{});
CharSequence[] entryValues = hMap.values().toArray(new CharSequence[]{});
lp.setEntries(entries);
lp.setEntryValues(entryValues);
}
public void setListPrefContatti(Context context, ListPreference lp) {
// Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(this);
lp.setOnPreferenceChangeListener(this);
// Trigger the listener immediately with the preference's
// current value.
onPreferenceChange(preference, PreferenceManager.getDefaultSharedPreferences(preference.getContext()).getString(preference.getKey(), ""));
onPreferenceChange(lp, PreferenceManager.getDefaultSharedPreferences(lp.getContext()).getString(lp.getKey(), ""));
String displayName = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? ContactsContract.Contacts.DISPLAY_NAME_PRIMARY : ContactsContract.Contacts.DISPLAY_NAME;
Cursor phones = context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, displayName + " ASC");
// use the cursor to access the contacts
SortedMap<String, String> hMap = new TreeMap<>();
while (phones.moveToNext())
{
String name=phones.getString(phones.getColumnIndex(displayName));
// get display name
String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
// get phone number
hMap.put(name, phoneNumber);
}
CharSequence[] entries = hMap.keySet().toArray(new CharSequence[]{});
CharSequence[] entryValues = hMap.values().toArray(new CharSequence[]{});
lp.setEntries(entries);
//lp.setDefaultValue("1");
lp.setEntryValues(entryValues);
}
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//getLoaderManager().initLoader(0, null, this);
getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
}
......
package it.giacomo.sesamo.managers;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import it.giacomo.sesamo.MainActivity;
import it.giacomo.sesamo.R;
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "FirebaseMessagingSrv";
......@@ -31,5 +39,19 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See sendNotification method below.
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_home_black_24dp)
.setContentTitle("Sesamo")
.setContentText("OPEN :-)");
Intent notificationIntent = new Intent(this, MainActivity.class);
// PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
// builder.setContentIntent(contentIntent);
// Add as notification
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, builder.build());
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="it.giacomo.sesamo.MainActivity">
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:text="@string/title_home" />
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
<TextView
android:id="@+id/timer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:menu="@menu/navigation" />
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="10"
android:fontFamily="sans-serif"
android:textSize="70dp"
android:layout_above="@+id/button2" />
</LinearLayout>
<Button
android:id="@+id/btnEsci"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:fontFamily="sans-serif"
android:textSize="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:text="Esci"
android:layout_alignParentEnd="true" />
</RelativeLayout>
......@@ -4,8 +4,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="it.giacomo.sesamo.Main2Activity"
tools:showIn="@layout/activity_main2">
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/navigation_home"
android:icon="@drawable/ic_home_black_24dp"
android:title="@string/title_home" />
<item
android:id="@+id/navigation_dashboard"
android:icon="@drawable/ic_dashboard_black_24dp"
android:title="@string/title_dashboard" />
<item
android:id="@+id/navigation_notifications"
android:icon="@drawable/ic_notifications_black_24dp"
android:title="@string/title_notifications" />
</menu>
<resources>
<string name="app_name">sesamo</string>
<string name="title_home">Home</string>
<string name="title_dashboard">Dashboard</string>
<string name="title_notifications">Notifications</string>
<string name="pref_send_report">Send crash reports</string>
<string name="pref_send_report_summary">Helps to fix bugs</string>
<string name="pref_sync_frequency">Sync frequency</string>
<string name="pref_sync_frequency_summary">Set the sync frequency</string>
<string name="pref_user_name">Set username</string>
<string name="pref_user_name_summary">Set your username</string>
<string name="pref_update_setting">Update Settings</string>
<string name="pref_operatore">Operatore</string>
<string name="pref_title_social_recommendations">Enable social recommendations</string>
<string name="pref_description_social_recommendations">Recommendations for people to contact based on your message history</string>
<string name="pref_title_display_name">Display name</string>
<string name="pref_default_display_name">Bülent Siyah</string>
<string name="title_activity_main2">Main2Activity</string>
<string name="title_activity_main1">Main1Activity</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="Numero per gli SMS" >
<EditTextPreference
android:title="Numero per gli SMS"
android:summary="+39..."
android:key="numero_sms"/>
</PreferenceCategory>
<PreferenceCategory android:title="Impostazioni fondamentali" >
<PreferenceCategory android:title="@string/pref_update_setting" >
<ListPreference
android:key="prefContatto"
android:summary="Imposta il numero per l'invio degli SMS"
android:title="Contatto" />
<ListPreference
android:key="prefOperatori"
android:entries="@array/numeroSim"
android:summary="Sim default"
android:entryValues="@array/numeroSimValues"
android:key="prefOperatore"
android:summary="Imposta la sim di default"
android:title="Sim impostata" />
</PreferenceCategory>
</PreferenceScreen>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment