vendredi 28 juillet 2017

Vue.JS Multiple checkbox series to filter apps

so here's my problem, I want to apply three filters to app thumbnails using Vue.js (I never used that framework before). It works fine for the first filter but I don't know how to proceed for the other ones. The goal is to be able to pick only one checkbox from each category (Platform, Field of activity and Device).

Screenshot of what it should look like. ("Toutes" meaning "All")

Here's the HTML

<div id="filter-realisations">
          <div id="filter">
            <div class="filter_container">
              <h3>Filtrer</h3>
              <div class="filter">
                <p>Plateforme</p>
                <input type="radio" v-model="selectedPlatform" value="AllPlatform" id="AllPlatform"><label for="AllPlatform">Toutes</label>
                <input type="radio" v-model="selectedPlatform" value="iOS" id="iOS" /><label for="iOS">iOS</label>
                <input type="radio" v-model="selectedPlatform" value="Android" id="Android" /><label for="Android">Android</label>
              </div>
              <div class="filter">
                <p>Secteur</p>
                <input type="radio" v-model="selectedSecteur" value="AllSecteur" id="AllSecteur" /><label for="AllSecteur">Toutes</label>
                <input type="radio" v-model="selectedSecteur" value="grandPublic" id="grandPublic"/><label for="grandPublic">Grand public</label>
                <input type="radio" v-model="selectedSecteur" value="metier" id="metier" /><label for="metier">Métier</label>
                <input type="radio" v-model="selectedSecteur" value="marchesPublics" id="marchesPublics" /><label for="marchesPublics">Marchés Publics</label>

              </div>
              <div class="filter">
                <p>Device</p>
                <input type="radio" v-model="selectedDevice" value="AllDevice" id="AllDevice" /><label for="AllDevice">Toutes</label>
                <input type="radio" v-model="selectedDevice" value="Smartphone" id="Smartphone" /><label for="Smartphone">Smartphone</label>
                <input type="radio" v-model="selectedDevice" value="Tablet" id="Tablet" /><label for="Tablet"> Tablette</label>
                <input type="radio" v-model="selectedDevice" value="Watch" id="Watch" /><label for="Watch"> Montre connectée</label>

              </div>
            </div>

          </div>

          <div id="realisations">
            <div class="realisations_container">
              <div class="realisations_bloc" v-for="app in filteredRealisations" v-bind:key="app">
                <img v-bind:src='"img/realisations/"+app.name+".jpg"' alt="app.name">
                <div class="overlay">
                  <div class="app_description"><p></p></div>
                  <div class="platform_container">
                     <div class="device">
                      <img v-bind:src='"img/"+app.device+".svg"' alt="app.device"/>
                    </div>
                    <div class="os">
                      <img v-bind:src='"img/"+app.platform+".svg"'alt="app.platform"/>
                    </div></div>
                </div>
              </div>

            </div>
          </div>
        </div>

And here's the script

var vm = new Vue({
    el:  "#filter-realisations",
    data: {
        realisations: [
            { name: "ASM", platform: "iOS", secteur: "grandPublic", secteur: "grandPublic", device:"Watch" },
            { name: "Biodiversea", platform: "Android", secteur: "marchesPublics", device:"Tablet" },
            { name: "CDBB", platform: "iOS", secteur: "grandPublic", device:"Smartphone" },
            { name: "Centre France", platform: "iOS", secteur: "grandPublic", device:"Watch" },
            { name: "Clermont", platform: "Android", secteur: "grandPublic", device:"Tablet" },
            { name: "Dassault", platform: "iOS", secteur: "metier", device:"Smartphone"},
            { name: "Journal", platform: "iOS", secteur: "metier", device:"Smartphone" },
            { name: "Somfy", platform: "Android", secteur: "metier", device:"Smartphone" },
            { name: "Sortir.vosges", platform: "Android", secteur: "metier", device:"Smartphone" },
      { name: "Sud Radio", platform: "Android", secteur: "metier", device:"Smartphone" },
      { name: "Verifrom", platform: "Android", secteur: "metier", device:"Smartphone" },
      { name: "Sports", platform: "iOS", secteur: "marchesPublics", device:"Watch" }

        ],
        selectedSecteur : "AllSecteur",
        selectedPlatform: "AllPlatform",
        selectedDevice : "AllDevice"
    },
    computed: {
        filteredRealisations: function() {
            var vm = this;
            var platform = vm.selectedPlatform;
            var secteur = vm.selectedSecteur;
            var device = vm.selectedDevice;



            if(platform === "AllPlatform") {
                return vm.realisations;
            } else {
                return vm.realisations.filter(function(app) {
                    return app.platform === platform;
                });
            }

            if(secteur === "AllSecteur") {
                return vm.realisations;
            } else {
                return vm.realisations.filter(function(app) {
                    return app.secteur === secteur;
                });
            }

            if(device === "AllDevice") {
                return vm.realisations;
            } else {
                return vm.realisations.filter(function(app) {
                    return app.device === device;
                });
            }

        }
    }
});




How to get all selected checkbox from a ExpandableListView in Android?

I have an ExpandableListView that has groups and itens, each iten has a checkbox that can be selected and I want to know how can I iterate over all itens and get their values when I click the button.

So far I have created the list, I already can select the checkboxes and everything is going well, but I cant find a solution to get the values from the checkboxes when I click the button. This is like a questionary, when the user finishes picking his choices, he will submit the values.

I have a MainActivity, an ExpandableListAdapter that is my list adapter implementation and I have 3 xml, activity_main.xml, list_group.xml and list_itens.xml.

Here is my code so far:

public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context context;
private List<String> listaDePerguntas;
private HashMap<String, List<String>> listaDeRespostas;
private CheckBox check;   

public ExpandableListAdapter(Context context, List<String> listaDePerguntas, HashMap<String, List<String>> listaDeRespostas) {
    this.context = context;
    this.listaDePerguntas = listaDePerguntas;
    this.listaDeRespostas = listaDeRespostas;
}

@Override
public int getGroupCount() {
    return listaDePerguntas.size();
}

@Override
public int getChildrenCount(int groupPosition) {
    return listaDeRespostas.get(listaDePerguntas.get(groupPosition)).size();
}

@Override
public Object getGroup(int groupPosition) {
    return listaDePerguntas.get(groupPosition);
}

@Override
public Object getChild(int groupPosition, int childPosition) {
    return listaDeRespostas.get(listaDePerguntas.get(groupPosition)).get(childPosition);
}

@Override
public long getGroupId(int groupPosition) {
    return groupPosition;
}

@Override
public long getChildId(int groupPosition, int childPosition) {
    return childPosition;
}

@Override
public boolean hasStableIds() {
    return false;
}

@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    String resposta = (String) getChild(groupPosition, childPosition);
    if(convertView == null) {
        LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.list_itens, null);
    }
    TextView text = (TextView) convertView.findViewById(R.id.listItem);
    text.setText(resposta);
    return convertView;
}

@Override
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    String resposta = (String) getChild(groupPosition, childPosition);

    if(convertView == null) {
        LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.list_itens, null);
    }
    TextView text = (TextView) convertView.findViewById(R.id.listItem);
    text.setText(resposta);

    CheckBox check = (CheckBox) convertView.findViewById(R.id.listCheckItem);
    //check.setFocusable(false);

    check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            Toast.makeText(buttonView.getContext(), "Selected! - Question number: " + groupPosition + "answer: " + childPosition + "ischecked: " + isChecked, Toast.LENGTH_SHORT).show();

        }
    });
    return convertView;
}

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    return true;
}

}

My MainActivity class:

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private ExpandableListView listView;
    private ExpandableListAdapter listAdapter;

    private List<String> perguntas;
    private HashMap<String, List<String>> respostas;

    private Button enviarRespostas;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    listView = (ExpandableListView) findViewById(R.id.expandableListView);

    carregarDados();

    listAdapter = new ExpandableListAdapter(this, perguntas, respostas);
    listView.setAdapter(listAdapter);

    listView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
            Toast.makeText(MainActivity.this, "Clicou no:" + groupPosition + " item: " + childPosition, Toast.LENGTH_SHORT).show();
            return false;
        }
    });

    listView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
        @Override
        public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
            Toast.makeText(MainActivity.this, "Clicou no:" + groupPosition, Toast.LENGTH_SHORT).show();
            return false;
        }
    });

    enviarRespostas = (Button) findViewById(R.id.buttonEnviarRespostas);
    enviarRespostas.setOnClickListener(this);

}


private void carregarDados() {
    perguntas = new ArrayList<>();
    respostas = new HashMap<>();

    perguntas.add("Pertunta 1");
    perguntas.add("Pertunta 2");
    perguntas.add("Pertunta 3");
    perguntas.add("Pertunta 4");

    List<String> respostasPergunta1 = new ArrayList<>();
    respostasPergunta1.add("Sim");
    respostasPergunta1.add("Não");
    respostasPergunta1.add("Talvez");

    List<String> respostasPergunta2 = new ArrayList<>();
    respostasPergunta2.add("10");
    respostasPergunta2.add("20");
    respostasPergunta2.add("30");
    respostasPergunta2.add("40");

    List<String> respostasPergunta3 = new ArrayList<>();
    respostasPergunta3.add("Sim");
    respostasPergunta3.add("Não");

    List<String> respostasPergunta4 = new ArrayList<>();
    respostasPergunta4.add("10");
    respostasPergunta4.add("20");
    respostasPergunta4.add("30");
    respostasPergunta4.add("40");
    respostasPergunta4.add("50");
    respostasPergunta4.add("60");

    respostas.put(perguntas.get(0), respostasPergunta1);
    respostas.put(perguntas.get(1), respostasPergunta2);
    respostas.put(perguntas.get(2), respostasPergunta3);
    respostas.put(perguntas.get(3), respostasPergunta4);
}

@Override
public void onClick(View v) {
    //todo
}

}

And here are my 3 .xml files:

1) activity_main.xml

<LinearLayout xmlns:android="http://ift.tt/nIICcg"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:padding="10dp"
    android:weightSum="1">


<ExpandableListView
    android:id="@+id/expandableListView"
    android:layout_width="match_parent"
    android:layout_height="437dp" />

<Button
    android:id="@+id/buttonEnviarRespostas"
    android:layout_width="match_parent"
    android:layout_height="35dp"
    android:text="Button" />

</LinearLayout>

2) list_group.xml

<LinearLayout xmlns:android="http://ift.tt/nIICcg"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="8dp"
    android:background="@android:color/white">

    <TextView
        android:id="@+id/header"
        android:paddingLeft="?
        android:attr/expandableListPreferredItemPaddingLeft"
        android:textSize="16dp"
        android:textColor="@android:color/black"
        android:layout_width="match_parent"
        android:layout_height="/>

</LinearLayout>

3) list_itens.xml

<TableLayout xmlns:android="http://ift.tt/nIICcg"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:stretchColumns="0">

    <TableRow>
        <TextView
            android:id="@+id/listItem"
            android:textSize="16dp"
            android:paddingLeft="?
            android:attr/expandableListPreferredChildPaddingLeft"
            android:paddingTop="5dp"
            android:paddingBottom="5dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <CheckBox
            android:id="@+id/listCheckItem"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginRight="50dp" />
    </TableRow>
</TableLayout>




jeudi 27 juillet 2017

Displaying checkbox data when clicked

I'm trying to make multiple select with checkbox ... if I click checkbox A then checkbox B follow click too. But only the A checkbox that appears, the B checkbox I created in a hidden state with css ..

<button type="button" id="delete" title="Delete">Delete</button>

<input type="checkbox" class="select_data"  id="A" name="A[]" value="A" />
<input type="checkbox" id="B" name="B[]" value="B">

$('#delete').click(function() {
        if($('#A').is(":checked")) {
            $('#B').attr('checked', true).val();
         }

    var data = $(".select_data:checked, .info_del:checked").serialize();
    console.log(data);       
});




Android onCheckedChangeListener bizarre behavior

So I am attempting to code some CheckBox logic for a page in which a user can +1 or -1 a specific entry. The first time my RecyclerViewAdapter is bound, I iterate through the list of votes and check if the user id is present, and if the vote value is +1 or -1 here

fun bindTask(lunchVote: LunchVoteGroupDestination) {
        mItem = lunchVote
        mIdView.text = lunchVote.groupDestination?.nickname
        mScoreView.text = lunchVote.score.toString()
        destinationId = lunchVote.groupDestinationId
        votes = lunchVote.votes

        for(vote: Vote in votes) {
            if(prefs!!.currentId == vote.userId && vote.voteValue == 1) {
                plusOneBox.setOnCheckedChangeListener(null)
                plusOneBox.isChecked = true
            }
            if (vote.userId.equals(prefs!!.currentId) && vote.voteValue == -1) {
                minusOneBox.setOnCheckedChangeListener(null)
                minusOneBox.isChecked = true
            }
        }

Which works fine! If I previously voted +1 and reload, boom, the box is checked. The issue, however, comes when I then try to interact with the boxes again. If I hit the +1 box, the check remains and doesnt do anything. This also occurs for the -1 box. I also set my listeners for the CheckBoxes in the bindtask function like so

fun bindTask(lunchVote: LunchVoteGroupDestination) {
        mItem = lunchVote
        mIdView.text = lunchVote.groupDestination?.nickname
        mScoreView.text = lunchVote.score.toString()
        destinationId = lunchVote.groupDestinationId
        votes = lunchVote.votes

        for(vote: Vote in votes) {
            if(prefs!!.currentId == vote.userId && vote.voteValue == 1) {
                plusOneBox.setOnCheckedChangeListener(null)
                plusOneBox.isChecked = true
            }
            if (vote.userId.equals(prefs!!.currentId) && vote.voteValue == -1) {
                minusOneBox.setOnCheckedChangeListener(null)
                minusOneBox.isChecked = true
            }
        }

        System.out.println("PlusOneBox " + plusOneBox.isChecked + mIdView.text)
        plusOneBox.setOnCheckedChangeListener(object : CompoundButton.OnCheckedChangeListener {
            override fun onCheckedChanged(buttonView: CompoundButton, isChecked: Boolean) {
                System.out.println("PLUSONE CHECKED")
                if(isChecked) {
                    val upvoteData = VoteObject(prefs!!.accessToken, prefs!!.currentGroup, prefs!!.currentLunchVote, destinationId)
                    socket.upvote(upvoteData)
                } else {
                    val downvoteData = VoteObject(prefs!!.accessToken, prefs!!.currentGroup, prefs!!.currentLunchVote, destinationId)
                    socket.downvote(downvoteData)
                }
            }
        })

        minusOneBox.setOnCheckedChangeListener(object : CompoundButton.OnCheckedChangeListener {
            override fun onCheckedChanged(buttonView: CompoundButton, isChecked: Boolean) {
                System.out.println("MINUSONE CHECKED")
                if(isChecked) {
                    val downvoteData = VoteObject(prefs!!.accessToken, prefs!!.currentGroup, prefs!!.currentLunchVote, destinationId)
                    socket.downvote(downvoteData)
                } else {
                    minusOneBox.setOnCheckedChangeListener(null)
                    val upvoteData = VoteObject(prefs!!.accessToken, prefs!!.currentGroup, prefs!!.currentLunchVote, destinationId)
                    socket.upvote(upvoteData)
                    minusOneBox.setOnCheckedChangeListener(this)
                }
            }
        })
    }

It should also be worth mentioning that I have a socket listener in my fragment class that uses the adapter listening for a +1 and -1 event, in which case it updates the score of the item and notifys the adapter that the data set has changed, like here

private val onUpvote = Emitter.Listener { args ->
    val data = args[0] as JSONObject
    var newScore: Int
    var updatedId: Int
    System.out.println(data)
    if(activity != null) {
        activity.runOnUiThread({
            try {
                newScore = data.getInt("score")
                updatedId = data.getInt("id")
                for (i in LUNCHVOTE_DESTINATIONS.size - 1 downTo 0) {
                    val destination = LUNCHVOTE_DESTINATIONS.get(i)
                    if(updatedId == destination.id) {
                        LUNCHVOTE_DESTINATIONS.get(i).score = newScore
                        recyclerView!!.adapter.notifyItemChanged(i, LUNCHVOTE_DESTINATIONS.get(i))
                        break
                    }
                }
            } catch (e: JSONException) {
                e.printStackTrace()
            }
        })
    }
}

Can any of you see why my CheckBoxes work fine when nothing is previously selected, but on a page reload it takes multiple clicks just to uncheck the boxes. Does it have to do with notifying the data set has changed in my listener. Am I binding the listeners multiple times so it's messing with my logic? Is my checkbox logic simply wrong? Any help here would be much appreciated.




using checkbox in materialize css, and page disappears after toggling the check box

I'm using a checkbox in my html from just lick this:

<div class="input-field col s12 m6 right">
    <input type="checkbox" id="myCheckbox" class="filled-in" />
    <label for="myCheckbox">label text</label>
</div>

but when I click on the checkbox,page disappears and get blank and I when i refresh again, page still is blank, is there any way to solve this?




Daily Notification even after cancel does not cancel it for next day

I have created a repeating daily notification. Everything works fine but when my checkbox is unchecked it cancel the alarm for that day and fire the notification next day for the same time.What i want is to cancel alarm if my checkbox is unchecked until i will checked it again.

This is my Setting Activity class.Here,I have set the time on clicking the checkbox.And i have called cancelAlarm method when the checkbox is unchecked.

public class SettingActivity extends AppCompatActivity {
public static int hour;
public static int minute;
private boolean check = false;
private int hour_1,minute_1;
static final int TIME_DIALOG_ID = 1111;
final Calendar c = Calendar.getInstance();
DatabaseAdapter MyHelper;
SharedPreferenceManager sharedPreferenceManager;
TextView textView_clearAllData;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_setting);
    textView_clearAllData = (TextView) 
    findViewById(R.id.textView_clearAllData);
    MyHelper=new DatabaseAdapter(getApplicationContext());

    context=this;


    sharedPreferenceManager  = new SharedPreferenceManager();

    if( 
      Boolean.valueOf(sharedPreferenceManager.getPreferences
        (SettingActivity.this,"check")))
      {
        CheckBox box = (CheckBox) 
       findViewById(R.id.checkBox_settingClassNotification);
        box.setChecked(true);
    }
    hour_1 = c.get(Calendar.HOUR_OF_DAY);
    minute_1 = c.get(Calendar.MINUTE);




  }

 public void onClick_dailyClassNotification(View view) {
    boolean checked = ((CheckBox) view).isChecked();
    switch (view.getId()) {
        case R.id.checkBox_settingClassNotification:
            if (checked) {
               // ((CheckBox) view).setChecked(false);    //initially 
    checkbox wont be checked
                showDialog(TIME_DIALOG_ID);
            }
            else
            {
                check = false;
                sharedPreferenceManager.setPreferences
           (SettingActivity.this,"check",String.valueOf(check));
                Notification_service.cancelAlarm(context);
                 Toast.makeText(SettingActivity.this, "Notification 
      Cancelled" ,Toast.LENGTH_SHORT).show();

            }
    }
 }

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
        case TIME_DIALOG_ID:
            // set time picker as current time
            TimePickerDialog myTime = new TimePickerDialog(this, 
 timePickerListener,
                    hour_1, minute_1, false);
            myTime.setOnCancelListener(new 
 DialogInterface.OnCancelListener(){
                CheckBox checkBox = (CheckBox) 
findViewById(R.id.checkBox_settingClassNotification);
                public void onCancel(DialogInterface dialog) {
                    //Log.d("IN HERE","HERE2");
                    checkBox.setChecked(false);
                    sharedPreferenceManager.setPreferences
        (SettingActivity.this,"check",String.valueOf(check));
                    //checkBox.setText("Use reminders");
                }
            });
            return myTime;
    }
    return null;
}

 private TimePickerDialog.OnTimeSetListener timePickerListener =
        new TimePickerDialog.OnTimeSetListener() {

            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int 
        minutes) {
                hour = hourOfDay;
                minute = minutes;

                sharedPreferenceManager.setPreferences
        (SettingActivity.this,"hour",Integer.toString(hour));
                sharedPreferenceManager.setPreferences
      (SettingActivity.this,"minute",Integer.toString(minute));

                //Making checkbox checked and svaing in sharedPreference
                CheckBox ch = 
 (CheckBox)findViewById(R.id.checkBox_settingClassNotification);
                ch.setChecked(true);
                check = true;

      sharedPreferenceManager.setPreferences
 (SettingActivity.this,"check",String.valueOf(check));

                createNotify();
                Toast.makeText(SettingActivity.this, "Notification Enabled 
    at " + hour + ":" + minute, Toast.LENGTH_SHORT).show();
            }

        };

public void createNotify() {
    Intent in = new Intent(this,Notification_service.class);
    startService(in);
}

   //clear All Data
 public void clearAllData() {
    long id = MyHelper.clearAllData();
    if(id<0)
        Message.message(getApplicationContext(),"Error");
    else
        Message.message(getApplicationContext(),"All Data Cleared !");
 }
  public void createDeleteDialog(View view){
    final AlertDialog.Builder dialogBuilder = new 
      AlertDialog.Builder(context);
    dialogBuilder.setTitle("Delete All Data ?");


    dialogBuilder.setPositiveButton("Yes", new 
       DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            clearAllData();
        }
    });
    dialogBuilder.setNegativeButton("Cancel", new 
     DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.dismiss();
        }
    });
    AlertDialog b = dialogBuilder.create();
    b.show();
  }


   }

This is my Notification service class where i have set daily alarm and cancel it with the same request Id.

   public class Notification_service extends Service {

SharedPreferenceManager sharedPreferenceManager;
private static final String TAG = "MyService";
int hour,minute;
/**
 * The started service starts the AlarmManager.
 */
public static AlarmManager alarmManager;
public static PendingIntent pendingIntent;
@Override
public void onStart(Intent intent, int startid) {
    sharedPreferenceManager = new SharedPreferenceManager();

    hour = Integer.parseInt(sharedPreferenceManager.getPreferences(Notification_service.this,"hour"));
    minute = Integer.parseInt(sharedPreferenceManager.getPreferences(Notification_service.this,"minute"));

    //the hour and minute variables came from setting activity. Use wherever required.
    long _alarm ;
    Calendar now = Calendar.getInstance();
    Calendar c = Calendar.getInstance();
    c.set(Calendar.HOUR_OF_DAY,hour);
    c.set(Calendar.MINUTE,minute);
    c.set(Calendar.SECOND,0);

    if(c.getTimeInMillis() <= now.getTimeInMillis())
       _alarm = c.getTimeInMillis() + (24*60*60*1000);
     else
        _alarm = c.getTimeInMillis();

    Intent i = new Intent(this, Notification_Receiver.class);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    /*PendingIntent*/ pendingIntent=PendingIntent.getBroadcast(getApplicationContext(),100,i,PendingIntent.FLAG_UPDATE_CURRENT);
    /*AlarmManager*/ alarmManager=(AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,_alarm,AlarmManager.INTERVAL_DAY,pendingIntent);

    // Toast.makeText(this, "Service started", Toast.LENGTH_LONG).show();
    // Log.d(TAG, "onStart");
}

//cancel alarm
public static void cancelAlarm(Context context) {

    /*if(alarmManager != null)
        alarmManager.cancel(pendingIntent);*/
    Intent i = new Intent(context, Notification_Receiver.class);

     pendingIntent=PendingIntent.getBroadcast(context,100,i,PendingIntent.FLAG_UPDATE_CURRENT);
     alarmManager=(AlarmManager) context.getSystemService(ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
}

@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public void onDestroy() {
    //Toast.makeText(this, "My Service stopped", Toast.LENGTH_LONG).show();
    // Log.d(TAG, "onDestroy");
}

}

This is my Notification Receiver class where i have set the Notification.

 public class Notification_Receiver extends BroadcastReceiver {
private Uri soundURI =
        Uri.parse("android.resource://com.example.homedemo/"
                + R.raw.gets_in_the_way);
private long[] mVibratePattern = { 0, 200, 200, 300 };
/*String[] day = {
        "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};*/
@Override
public void onReceive(Context context, Intent intent) {

    NotificationManager notificationManager= (NotificationManager)
            context.getSystemService(Context.NOTIFICATION_SERVICE);

    /*Calendar calendar = Calendar.getInstance();
    int d = calendar.get(Calendar.DAY_OF_WEEK);
    Log.d("day = ",Integer.toString(d));
    */
    Intent repeating_intent=new Intent(context,HomeActivity.class);
    /*Intent repeating_intent = new Intent(context,RoutineOfTheDayActivity.class);
    String day_str = day[d];
    repeating_intent.putExtra("day",day_str);
    */
    repeating_intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent=PendingIntent.
            getActivity(context,100,repeating_intent,PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder= (NotificationCompat.Builder) new NotificationCompat.Builder(context)
            .setContentIntent(pendingIntent)
            .setContentTitle("Your today's classes").setContentText("Touch here to see schedule")
            .setAutoCancel(true).setSmallIcon(android.R.drawable.arrow_up_float)
            .setSound(soundURI)
            .setVibrate(mVibratePattern);
    notificationManager.notify(100,builder.build());

}

}




auto slide out with checkbox in jquery

I'm a rookie in jquery and want to learn for myself. I have red box using with checkbox inside of the red box.

what I like to have is that when load the page while uncheck, is automatic red box slide out if the user wants to slide in all have to do is mouse over on red box slide in.

I also have a checkbox for turn off automatic slide out, another word means stay view with out slide out.

I have written code but is not working, I guess it must merge two jquerys for ( slideout and checkbox)... I need help to have both auto slideout or slide in with checkbox that if checkbox checked then turn off auto slideout or slide in.

see jsfiddle

see the code ...

<!--auto hide and show right sidebar-->   

$(window).on("load", function() {
   $(".sidebar-nav-right").animate({ "right": "-=150px" }, "slow" );
});

$(window).on("load", function() {
   $(".sidebar-nav-right").animate({ "right": "-=150px" }, "fast" );
});


$(".sidebar-nav-right").hover(function () {
    $(".sidebar-nav-right").animate({ "right": "0px" }, "fast" );
}, function(){
     $(".sidebar-nav-right").animate({ "right": "-=150px" }, "fast" );
});


<!--checkbox -->

$('#mycheckbox').change(function(){
  if($(this).prop("checked")) {
    $(".sidebar-nav-right").addClass("sidebar-nav-rightb");
    $(".ui-sortable").css("width", "1320px");
  } else {
    $(".sidebar-nav-right").removeClass("sidebar-nav-rightb");
     $(".ui-sortable").css("width", "100%");
  }
});

<div class="sidebar-nav-right">

<div><input type="checkbox" id"mycheckbox">checkbox</div>

right sidebar

</div>