Commit 6aed6939 authored by Giacomo Lavermicocca's avatar Giacomo Lavermicocca Committed by Pietro Saccardi

Others test

parent da7ee0f8
......@@ -29,8 +29,11 @@ dependencies {
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-vector-drawable:25.3.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
\ No newline at end of file
package it.giacomo.sesamo;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("it.giacomo.sesamo", appContext.getPackageName());
}
}
......@@ -13,31 +13,34 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:name=".SettingsActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
<service
android:name=".managers.MyFirebaseMessagingService">
<service android:name=".managers.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<receiver android:name=".MainActivityWidget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"></action>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/mywidget"></meta-data>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/mywidget" />
</receiver>
<activity
android:name=".SettingsActivity"
android:label="@string/app_name">
android:name=".Main1Activity"
android:label="@string/title_activity_main1"
android:theme="@style/AppTheme.NoActionBar"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......
package it.giacomo.sesamo;
import android.os.Bundle;
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.view.View;
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();
}
});
}
}
......@@ -2,6 +2,7 @@ package it.giacomo.sesamo;
import android.app.Activity;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
import android.content.ContentValues;
import android.content.Context;
......@@ -40,7 +41,17 @@ public class MainActivity extends AppCompatActivity {
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);
......@@ -50,12 +61,28 @@ public class MainActivity extends AppCompatActivity {
}
};
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+"");
}
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();
FirebaseMessaging.getInstance().subscribeToTopic("OPEN");
mTextMessage = (TextView) findViewById(R.id.message);
......@@ -70,7 +97,11 @@ public class MainActivity extends AppCompatActivity {
List<SubscriptionInfo> t = sms.getSubscriptionList(getApplicationContext());
// SharedPreferences prefs = getSharedPreferences(MY_PREFERENCES, Context.MODE_PRIVATE);
// String textData = prefs.getString(TEXT_DATA_KEY, "No Preferences!");
sms.Do(2, "", null, "OPEN_2", null, null);
}
private void sendSMS(final String phoneNumber, final String message) {
......
......@@ -6,9 +6,13 @@ import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.RemoteViews;
import android.widget.Toast;
import java.util.Random;
/**
* Created by Giacomo on 26/08/2017.
*/
......@@ -17,18 +21,55 @@ 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 = "http://www.tutorialspoint.com";
String url = "it.giacomo.sesamo.MainActivity";
Intent intent = new Intent(Intent.ACTION_VIEW);
Intent intent = new Intent(context, SettingsActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse(url));
//intent.setData(Uri.parse(url));
PendingIntent pending = PendingIntent.getActivity(context, 0,intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.activity_main_widget);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.activity_main_widget);
views.setOnClickPendingIntent(R.id.btn_entro, pending);
appWidgetManager.updateAppWidget(currentWidgetId,views);
appWidgetManager.updateAppWidget(currentWidgetId, views);
Toast.makeText(context, "widget added", Toast.LENGTH_SHORT).show();
// 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);
Toast.makeText(context, "widget added", Toast.LENGTH_SHORT).show();
}
}
private PendingIntent makePIntent(Context context, int value)
{
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);
}
}
\ No newline at end of file
package it.giacomo.sesamo;
import android.appwidget.AppWidgetManager;
import android.content.Intent;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
......@@ -8,7 +10,6 @@ import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
public class SettingsActivity extends PreferenceActivity implements Preference.OnPreferenceChangeListener {
public static class MyPreferenceFragment extends PreferenceFragment
{
......@@ -18,25 +19,31 @@ public class SettingsActivity extends PreferenceActivity implements Preference.O
super.onCreate(savedInstanceState);
try{
addPreferencesFromResource(R.xml.settings);
SettingsActivity m = new SettingsActivity();
this.getPreferenceManager().getSharedPreferences();
m.bindPreferenceSummaryToValue(findPreference("prefUsername"));
final SettingsActivity m = new SettingsActivity();
m.bindPreferenceSummaryToValue(findPreference("numero_sms"));
}catch(Exception exp){
exp.toString();
}
}
}
@Override
public void onBackPressed() {
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
finish();
}
int mAppWidgetId;
private void bindPreferenceSummaryToValue(Preference preference) {
// Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(this);
// Trigger the listener immediately with the preference's
// current value.
onPreferenceChange(preference,
PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getString(preference.getKey(), ""));
onPreferenceChange(preference, PreferenceManager.getDefaultSharedPreferences(preference.getContext()).getString(preference.getKey(), ""));
}
@SuppressWarnings("deprecation")
......@@ -44,6 +51,14 @@ public class SettingsActivity extends PreferenceActivity implements Preference.O
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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);
}
}
@Override
......
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="it.giacomo.sesamo.Main1Activity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main1" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
......@@ -9,38 +9,36 @@
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:transitionGroup="true">
android:transitionGroup="true"
android:orientation="horizontal">
<Button
android:id="@+id/btn_entro"
android:id="@+id/btn_garage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="ENTRA" />
android:text="GARAGE"
android:theme="@style/MyButton" />
<Button
android:id="@+id/btn_esci"
android:id="@+id/btn_portone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/btn_entro"
android:layout_toEndOf="@+id/btn_entro"
android:text="ESCI" />
android:text="PORTONE"
android:theme="@style/MyButton" />
<Button
android:id="@+id/btn_garage"
android:id="@+id/btn_esci"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/btn_esci"
android:text="GARAGE" />
android:text="ESCI"
android:theme="@style/MyButton" />
<Button
android:id="@+id/btn_portone"
android:id="@+id/btn_entro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/btn_garage"
android:text="PORTONE" />
</RelativeLayout>
\ No newline at end of file
android:text="ENTRA"
android:theme="@style/MyButton" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="it.giacomo.sesamo.Main1Activity"
tools:showIn="@layout/activity_main1">
</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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: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">
</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="syncFrequency">
<item name="1">Once a day</item>
<item name="7">Once a week</item>
<item name="3">Once a year</item>
<item name="0">Never (Update maually)</item>
<string-array name="numeroSim">
<item name="0">Scelto al momento</item>
<item name="1">SIM 1</item>
<item name="2">SIM 2</item>
</string-array>
<string-array name="syncFrequencyValues">
<item name="1">1</item>
<item name="7">7</item>
<item name="30">30</item>
<string-array name="numeroSimValues">
<item name="0">0</item>
<item name="1">1</item>
<item name="2">2</item>
</string-array>
</resources>
......@@ -3,4 +3,5 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorWhite">#FFFFFF</color>
</resources>
......@@ -2,4 +2,5 @@
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
</resources>
......@@ -11,13 +11,15 @@
<string name="pref_user_name">Set username</string>
<string name="pref_user_name_summary">Set your username</string>
<string name="pref_user_profile">User Profile</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>
......@@ -8,4 +8,18 @@
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="MyButton" > <!--<parent="Theme.AppCompat.Light"-->
<item name="colorControlHighlight">@color/colorPrimary</item>
<item name="colorButtonNormal">@color/colorAccent</item>
<item name="android:textColor">@color/colorWhite</item>
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="146dp"
android:minWidth="320dp"
android:minHeight="40dp"
android:updatePeriodMillis="0"
android:previewImage="@drawable/preview"
android:initialLayout="@layout/activity_main_widget"
android:configure="it.giacomo.sesamo.SettingsActivity"
android:updatePeriodMillis="10000"
android:minHeight="146dp"
android:initialLayout="@layout/activity_main">
android:resizeMode="horizontal|vertical"
android:widgetCategory="home_screen">
</appwidget-provider>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="@string/pref_user_profile" >
<PreferenceCategory android:title="Numero per gli SMS" >
<EditTextPreference
android:title="@string/pref_user_name"
android:summary="@string/pref_user_name_summary"
android:key="prefUsername"/>
android:title="Numero per gli SMS"
android:summary="+39..."
android:key="numero_sms"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_update_setting" >
<CheckBoxPreference
android:defaultValue="false"
android:key="prefSendReport"
android:summary="@string/pref_send_report_summary"
android:title="@string/pref_send_report" >
</CheckBoxPreference>
<ListPreference
android:key="prefSyncFrequency"
android:entries="@array/syncFrequency"
android:summary="@string/pref_sync_frequency_summary"
android:entryValues="@array/syncFrequencyValues"
android:title="@string/pref_sync_frequency" />
android:key="prefOperatori"
android:entries="@array/numeroSim"
android:summary="Sim default"
android:entryValues="@array/numeroSimValues"
android:title="Sim impostata" />
</PreferenceCategory>
</PreferenceScreen>
\ No newline at end of file
package it.giacomo.sesamo;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
\ 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