Parcourir la source

Settings nb blink by star
Component creation UI StarRateView

sylvrec il y a 9 ans
Parent
commit
e2120339a2

+ 1 - 1
.idea/gradle.xml

@@ -5,7 +5,7 @@
       <GradleProjectSettings>
         <option name="distributionType" value="LOCAL" />
         <option name="externalProjectPath" value="$PROJECT_DIR$" />
-        <option name="gradleHome" value="C:\Program Files\Android\Android Studio\gradle\gradle-2.14.1" />
+        <option name="gradleHome" value="C:\Program Files\Android\android-studio\gradle\gradle-2.14.1" />
         <option name="modules">
           <set>
             <option value="$PROJECT_DIR$" />

+ 1 - 1
.idea/modules.xml

@@ -2,8 +2,8 @@
 <project version="4">
   <component name="ProjectModuleManager">
     <modules>
-      <module fileurl="file://$PROJECT_DIR$/InCallSmS.iml" filepath="$PROJECT_DIR$/InCallSmS.iml" />
       <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
+      <module fileurl="file://$PROJECT_DIR$/incallsms.iml" filepath="$PROJECT_DIR$/incallsms.iml" />
     </modules>
   </component>
 </project>

+ 4 - 0
.idea/vcs.xml

@@ -5,5 +5,9 @@
     <mapping directory="$PROJECT_DIR$" vcs="Git" />
     <mapping directory="$PROJECT_DIR$" vcs="Git" />
     <mapping directory="$PROJECT_DIR$" vcs="Git" />
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
   </component>
 </project>

+ 1 - 1
InCallSmS.iml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<module external.linked.project.id="InCallSmS" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+<module external.linked.project.id="incallsms" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
   <component name="FacetManager">
     <facet type="java-gradle" name="Java-Gradle">
       <configuration>

+ 1 - 0
app/app.iml

@@ -108,5 +108,6 @@
     </content>
     <orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
     <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" exported="" name="android-android-23" level="project" />
   </component>
 </module>

+ 5 - 4
app/src/main/java/com/sylvrec/incallsms/FlashLight.java

@@ -7,6 +7,7 @@ import android.hardware.Camera;
 import android.hardware.camera2.CameraAccessException;
 import android.hardware.camera2.CameraManager;
 
+import java.lang.annotation.Documented;
 import java.util.Timer;
 import java.util.TimerTask;
 
@@ -32,19 +33,19 @@ public class FlashLight {
         return  MyApp.getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
     }
 
-    public void Blink(final int nb) {
+    public void Blink(final int time, final int delay) {
         new Thread(new Runnable() {
             @Override
             public void run() {
-                for (int i=0; i<nb; i++) {
+                for (int i=0; i<time; i++) {
                     Open();
                     new Timer().schedule(new TimerTask() {
                         @Override
                         public void run() {
                             Close();
                         }
-                    }, 0, 1500);
-                    try { Thread.sleep(1500); } catch (InterruptedException e) {}
+                    }, 0, delay);
+                    try { Thread.sleep(delay); } catch (InterruptedException e) {}
                 }
             }
         }).start();

+ 3 - 3
app/src/main/java/com/sylvrec/incallsms/IncomingCallReceiver.java

@@ -20,15 +20,15 @@ public class IncomingCallReceiver extends BroadcastReceiver {
         Log.d("Test", intent.getAction());
         String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
         if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
-            new FlashLight().Blink(6);
+            new FlashLight().Blink(6, 1000);
             Log.d("Test", "onReceive --- RING --- ");
         }
         if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
-            new FlashLight().Blink(2);
+            new FlashLight().Blink(2, 1000);
             Log.d("Test", "onReceive --- SMS --- ");
         }
         if (intent.getAction().equals("android.provider.Telephony.WAP_PUSH_RECEIVED")) {
-            new FlashLight().Blink(3);
+            new FlashLight().Blink(3, 1000);
             Log.d("Test", "onReceive --- MMS --- ");
         }
     }

+ 0 - 23
app/src/main/java/com/sylvrec/incallsms/IncomingCallService.java

@@ -1,23 +0,0 @@
-package com.sylvrec.incallsms;
-
-import android.app.Service;
-import android.content.Intent;
-import android.os.IBinder;
-
-/**
- * Created by sylvain.reclus on 23/09/2016.
- */
-
-public class IncomingCallService extends Service {
-
-    @Override
-    public void onCreate() {
-        super.onCreate();
-        new IncomingCallReceiver();
-    }
-
-    @Override
-    public IBinder onBind(Intent intent) {
-        return null;
-    }
-}

+ 77 - 11
app/src/main/java/com/sylvrec/incallsms/MainActivity.java

@@ -2,24 +2,32 @@ package com.sylvrec.incallsms;
 
 import android.app.Activity;
 import android.app.AlertDialog;
-import android.content.Context;
 import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.IntentFilter;
 import android.content.pm.PackageManager;
-import android.hardware.camera2.CameraAccessException;
-import android.hardware.camera2.CameraManager;
 import android.os.Bundle;
-import android.os.Handler;
-import android.telecom.InCallService;
-import android.widget.Toast;
+import android.view.View;
+import android.widget.CompoundButton;
+import android.widget.LinearLayout;
+import android.widget.ToggleButton;
+
+import com.sylvrec.incallsms.UI.IOnCheckStarRateListener;
+import com.sylvrec.incallsms.UI.StarRateView;
 
 /**
  * Created by sylvain.reclus on 14/09/2016.
  */
 
-public class MainActivity extends Activity {
-    private FlashLight _light;
+public class MainActivity extends Activity implements IOnCheckStarRateListener, CompoundButton.OnCheckedChangeListener {
+    private ToggleButton _tbCall;
+    private ToggleButton _tbSms;
+    private ToggleButton _tbMms;
+    private LinearLayout _llCall;
+    private LinearLayout _llSms;
+    private LinearLayout _llMms;
+    private StarRateView _starRateViewCall;
+    private StarRateView _starRateViewSms;
+    private StarRateView _starRateViewMms;
+
     @Override
     protected void onStart() {
         super.onStart();
@@ -49,6 +57,35 @@ public class MainActivity extends Activity {
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main_activity);
+
+        _tbCall = (ToggleButton)findViewById(R.id.tbCall);
+        _tbSms = (ToggleButton)findViewById(R.id.tbSms);
+        _tbMms = (ToggleButton)findViewById(R.id.tbMms);
+
+        _llCall = (LinearLayout)findViewById(R.id.llCall);
+        _llSms = (LinearLayout)findViewById(R.id.llSms);
+        _llMms = (LinearLayout)findViewById(R.id.llMms);
+
+        _starRateViewCall = (StarRateView)findViewById(R.id.StarRateCall);
+        _starRateViewSms = (StarRateView)findViewById(R.id.StarRateSms);
+        _starRateViewMms = (StarRateView)findViewById(R.id.StarRateMms);
+
+        _tbCall.setOnCheckedChangeListener(this);
+        _tbSms.setOnCheckedChangeListener(this);
+        _tbMms.setOnCheckedChangeListener(this);
+
+        _starRateViewCall.SetOnCheckStarRateListener(this);
+        _starRateViewSms.SetOnCheckStarRateListener(this);
+        _starRateViewMms.SetOnCheckStarRateListener(this);
+
+        _tbCall.setChecked(true);
+        _tbSms.setChecked(true);
+        _tbMms.setChecked(true);
+
+        _starRateViewCall.SetValue(5);
+        _starRateViewSms.SetValue(5);
+        _starRateViewMms.SetValue(5);
+
         boolean hasFlash = getApplicationContext().getPackageManager()
                 .hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
 
@@ -67,7 +104,36 @@ public class MainActivity extends Activity {
             });
             alert.show();
         } else {
-            new FlashLight().Blink(2);
+            new FlashLight().Blink(2, 500);
+        }
+    }
+
+    @Override
+    public void OnCheckStar(View v, int n) {
+        switch (v.getId()){
+            case R.id.StarRateCall:
+                break;
+            case R.id.StarRateSms:
+                break;
+            case R.id.StarRateMms:
+                break;
+        }
+    }
+
+    @Override
+    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+        if (!isChecked) {
+            buttonView.setVisibility(View.GONE);
+        } else {
+            buttonView.setVisibility(View.VISIBLE);
+        }
+        switch (buttonView.getId()) {
+            case R.id.tbCall:
+                break;
+            case R.id.tbMms:
+                break;
+            case R.id.tbSms:
+                break;
         }
     }
 }

+ 11 - 0
app/src/main/java/com/sylvrec/incallsms/UI/IOnCheckStarRateListener.java

@@ -0,0 +1,11 @@
+package com.sylvrec.incallsms.UI;
+
+import android.view.View;
+
+/**
+ * Created by sylvr on 10/2/2016.
+ */
+
+public interface IOnCheckStarRateListener {
+    void OnCheckStar(View v, int n);
+}

+ 126 - 0
app/src/main/java/com/sylvrec/incallsms/UI/StarRateView.java

@@ -0,0 +1,126 @@
+package com.sylvrec.incallsms.UI;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.LinearLayout;
+
+import com.sylvrec.incallsms.R;
+
+/**
+ * Created by sylvr on 10/2/2016.
+ */
+
+public class StarRateView extends LinearLayout implements View.OnClickListener {
+    private Button[] _btnStar;
+    private Boolean[] _bStar;
+    private IOnCheckStarRateListener _onCheckStarRateListener;
+
+    public StarRateView(Context context) {
+        super(context);
+        Init(context);
+    }
+
+    public StarRateView(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        Init(context);
+    }
+
+    public StarRateView(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+        Init(context);
+    }
+
+    private void Init(Context context) {
+        inflate(context, R.layout.starrate_view, this);
+        _btnStar = new Button[10];
+        _bStar = new Boolean[10];
+        for (int i=0;i<10;i++) {
+            _bStar[i] = false;
+        }
+        _btnStar[0] = (Button)findViewById(R.id.star_0);
+        _btnStar[1] = (Button)findViewById(R.id.star_1);
+        _btnStar[2] = (Button)findViewById(R.id.star_2);
+        _btnStar[3] = (Button)findViewById(R.id.star_3);
+        _btnStar[4] = (Button)findViewById(R.id.star_4);
+        _btnStar[5] = (Button)findViewById(R.id.star_5);
+        _btnStar[6] = (Button)findViewById(R.id.star_6);
+        _btnStar[7] = (Button)findViewById(R.id.star_7);
+        _btnStar[8] = (Button)findViewById(R.id.star_8);
+        _btnStar[9] = (Button)findViewById(R.id.star_9);
+
+        for (int i=0;i<10;i++)
+            _btnStar[i].setOnClickListener(this);
+
+    }
+
+    @Override
+    public void onClick(View v) {
+        Log.d("TEST", "TEST COMMENT FUCKING GOD");
+        switch (v.getId()){
+            case R.id.star_0:
+                ChangeStateBtnStar(1);
+                break;
+            case R.id.star_1:
+                ChangeStateBtnStar(2);
+                break;
+            case R.id.star_2:
+                ChangeStateBtnStar(3);
+                break;
+            case R.id.star_3:
+                ChangeStateBtnStar(4);
+                break;
+            case R.id.star_4:
+                ChangeStateBtnStar(5);
+                break;
+            case R.id.star_5:
+                ChangeStateBtnStar(6);
+                break;
+            case R.id.star_6:
+                ChangeStateBtnStar(7);
+                break;
+            case R.id.star_7:
+                ChangeStateBtnStar(8);
+                break;
+            case R.id.star_8:
+                ChangeStateBtnStar(9);
+                break;
+            case R.id.star_9:
+                ChangeStateBtnStar(10);
+                break;
+            default:
+        }
+    }
+
+    public int GetValue() {
+        for (int i=0;i<10;i++) {
+            if (_bStar[i] != true) {
+                return i;
+            }
+        }
+        return 10;
+    }
+
+    public void SetValue(int j){
+        ChangeStateBtnStar(j);
+    }
+
+    public void SetOnCheckStarRateListener(IOnCheckStarRateListener onClickStarRateView) {
+        _onCheckStarRateListener = onClickStarRateView;
+    }
+
+    private void ChangeStateBtnStar(int j){
+        for (int i=0;i<j;i++){
+            _bStar[i] = true;
+            _btnStar[i].setForeground(getResources().getDrawable(android.R.drawable.btn_star_big_on));
+        }
+        for (int i=j;i<10;i++){
+            _bStar[i] = false;
+            _btnStar[i].setForeground(getResources().getDrawable(android.R.drawable.btn_star_big_off));
+        }
+        _onCheckStarRateListener.OnCheckStar(this, j);
+    }
+
+}

+ 148 - 0
app/src/main/res/layout/main_activity.xml

@@ -1,6 +1,154 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:orientation="vertical" android:layout_width="match_parent"
     android:layout_height="match_parent">
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="vertical">
+            <LinearLayout
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:orientation="horizontal">
+                <ImageView
+                    android:id="@+id/ivCall"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_gravity="center"
+                    android:src="@android:drawable/sym_action_call" />
+                <TextView
+                    android:layout_width="wrap_content"
+                    android:layout_height="match_parent"
+                    android:text="Call"
+                    android:textSize="42px"
+                    android:gravity="center"
+                    android:layout_marginLeft="5dp"/>
+                <View
+                    android:layout_width="0dp"
+                    android:layout_height="match_parent"
+                    android:layout_weight="8"/>
+                <ToggleButton
+                    android:id="@+id/tbCall"
+                    android:text="ToggleButton"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_gravity="center"
+                    android:layout_weight="1"/>
+            </LinearLayout>
+            <LinearLayout
+                android:id="@+id/llCall"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:orientation="vertical">
+                <TextView
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:text="Nb blink : "/>
+                <app:com.sylvrec.incallsms.UI.StarRateView
+                    android:id="@+id/StarRateCall"
+                    android:layout_width="match_parent"
+                    android:layout_height="30dp"/>
+            </LinearLayout>
+        </LinearLayout>
 
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="72px"
+            android:orientation="vertical">
+            <LinearLayout
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:orientation="horizontal">
+                <ImageView
+                    android:id="@+id/ivSMS"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_gravity="center"
+                    android:src="@android:drawable/sym_action_chat" />
+                <TextView
+                    android:layout_width="wrap_content"
+                    android:layout_height="match_parent"
+                    android:text="SMS"
+                    android:textSize="42px"
+                    android:gravity="center"
+                    android:layout_marginLeft="5dp"/>
+                <View
+                    android:layout_width="0dp"
+                    android:layout_height="match_parent"
+                    android:layout_weight="8"/>
+                <ToggleButton
+                    android:id="@+id/tbSms"
+                    android:text="ToggleButton"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_gravity="center"
+                    android:layout_weight="1"/>
+
+            </LinearLayout>
+            <LinearLayout
+                android:id="@+id/llSms"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:orientation="vertical">
+                <TextView
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:text="Nb blink : "/>
+                <app:com.sylvrec.incallsms.UI.StarRateView
+                    android:id="@+id/StarRateSms"
+                    android:layout_width="match_parent"
+                    android:layout_height="30dp"/>
+            </LinearLayout>
+        </LinearLayout>
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="72px"
+            android:orientation="vertical">
+            <LinearLayout
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:orientation="horizontal">
+                <ImageView
+                    android:id="@+id/ivMMS"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_gravity="center"
+                    android:src="@android:drawable/sym_action_email" />
+                <TextView
+                    android:layout_width="wrap_content"
+                    android:layout_height="match_parent"
+                    android:text="MMS"
+                    android:textSize="42px"
+                    android:gravity="center"
+                    android:layout_marginLeft="5dp"/>
+                <View
+                    android:layout_width="0dp"
+                    android:layout_height="match_parent"
+                    android:layout_weight="8"/>
+                <ToggleButton
+                    android:id="@+id/tbMms"
+                    android:text="ToggleButton"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_gravity="center"
+                    android:layout_weight="1"/>
+            </LinearLayout>
+            <LinearLayout
+                android:id="@+id/llMms"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:orientation="vertical">
+                <TextView
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:text="Nb blink : "/>
+                <app:com.sylvrec.incallsms.UI.StarRateView
+                    android:id="@+id/StarRateMms"
+                    android:layout_width="match_parent"
+                    android:layout_height="30dp"/>
+            </LinearLayout>
+        </LinearLayout>
 </LinearLayout>

+ 65 - 0
app/src/main/res/layout/starrate_view.xml

@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="horizontal" android:layout_width="match_parent"
+    android:layout_height="match_parent">
+    <Button
+        android:id="@+id/star_0"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="2"
+        android:foreground="@android:drawable/btn_star_big_off"/>
+    <Button
+        android:id="@+id/star_1"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="2"
+        android:foreground="@android:drawable/btn_star_big_off"/>
+    <Button
+        android:id="@+id/star_2"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="2"
+        android:foreground="@android:drawable/btn_star_big_off"/>
+    <Button
+        android:id="@+id/star_3"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="2"
+        android:foreground="@android:drawable/btn_star_big_off"/>
+    <Button
+        android:id="@+id/star_4"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="2"
+        android:foreground="@android:drawable/btn_star_big_off"/>
+    <Button
+        android:id="@+id/star_5"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="2"
+        android:foreground="@android:drawable/btn_star_big_off"/>
+    <Button
+        android:id="@+id/star_6"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="2"
+        android:foreground="@android:drawable/btn_star_big_off"/>
+    <Button
+        android:id="@+id/star_7"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="2"
+        android:foreground="@android:drawable/btn_star_big_off"/>
+    <Button
+        android:id="@+id/star_8"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="2"
+        android:foreground="@android:drawable/btn_star_big_off"/>
+    <Button
+        android:id="@+id/star_9"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="2"
+        android:foreground="@android:drawable/btn_star_big_off"/>
+</LinearLayout>

+ 1 - 1
app/src/main/res/values-v21/styles.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
-    <style name="AppTheme" parent="android:Theme.Material.Light">
+    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
     </style>
 </resources>