Skip to content

Instantly share code, notes, and snippets.

View frhan's full-sized avatar

Farhan Faruque frhan

View GitHub Profile
public void setCurrentWithClearTop(Class<?> klass,Bundle b)
{
Intent intentToBeNewRoot = new Intent(this, klass);
ComponentName cn = intentToBeNewRoot.getComponent();
Intent mainIntent = IntentCompat.makeRestartActivityTask(cn);
startActivity(mainIntent);
}
@frhan
frhan / android_hide_soft_keyboard
Created September 23, 2014 23:15
android- hide sof keyboard
public void hideSoftKeyboard()
{
InputMethodManager inputManager = (InputMethodManager)
getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
View v = getActivity().getCurrentFocus();
if(v == null)
return;
inputManager.hideSoftInputFromWindow(v.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
@frhan
frhan / android_custom_action_bar
Created September 23, 2014 22:19
custom action bar for android
private void setCustomActionbar()
{
actionBar.setLogo(null); // forgot why this one but it helped
View homeIcon = findViewById(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ?
android.R.id.home : android.support.v7.appcompat.R.id.home);
((View) homeIcon.getParent()).setVisibility(View.GONE);
((View) homeIcon).setVisibility(View.GONE);
@frhan
frhan / mongo_db_reapir
Created August 22, 2014 17:50
Reapir mongodb
Step 1: Remove lock file.
sudo rm /var/lib/mongodb/mongod.lock
Step 2: Repair mongodb.
mongod --repair
Step 3: start mongodb.
sudo start mongodb
or
sudo service mongodb start
Even if you haven't tracked the files so far, git seems to be able to "know" about them even after you add them to .gitignore.
A quick fix that I've used was to run the following commands from the top folder of your git repo:
(edited)
git rm -r --cached .
Followed by:
git add .
and
@frhan
frhan / DeviceListActivity.java
Last active August 29, 2015 13:56
Bluetooth discovery android
package com.sel.code;
import java.util.Set;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
public class OpenPdf extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.OpenPdfButton);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@frhan
frhan / android_viewpager_dynamic
Created January 1, 2014 21:01
Android dynamic view pager
After figuring out which ViewPager methods are called by ViewPager and which are for other purposes, I came up with a solution. I present it here since I see a lot of people have struggled with this and I didn't see any other relevant answers.
First, here's my adapter; hopefully comments within the code are sufficient:
class MainPagerAdapter extends PagerAdapter
{
// This holds all the currently displayable views, in order from left to right.
private ArrayList<View> views = new ArrayList<View>();
//-----------------------------------------------------------------------------