This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void showToastUnder(View v){ | |
Toast toast = Toast.makeText(v.getContext(), | |
v.getContentDescription(), Toast.LENGTH_SHORT); | |
toast.setGravity(Gravity.LEFT | Gravity.TOP, v.getLeft(), | |
v.getBottom() + v.getBottom() / 2); | |
toast.show(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Intent browserIntent = new Intent(Intent.ACTION_EDIT, Uri.parse("<a href="http://cafebazaar.ir/app/?id=" target="_blank">http://cafebazaar.ir/app/?id=</a>نام پکیج برنامه")); | |
startActivity(browserIntent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File k = new File(path, "mysong.mp3"); // path is a file to /sdcard/media/ringtone | |
ContentValues values = new ContentValues(); | |
values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath()); | |
values.put(MediaStore.MediaColumns.TITLE, "My Song title"); | |
values.put(MediaStore.MediaColumns.SIZE, 215454); | |
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3"); | |
values.put(MediaStore.Audio.Media.ARTIST, "Madonna"); | |
values.put(MediaStore.Audio.Media.DURATION, 230); | |
values.put(MediaStore.Audio.Media.IS_RINGTONE, true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void dial(String num){ | |
Intent callIntent = new Intent(Intent.ACTION_DIAL); | |
callIntent.setData(Uri.parse("tel:" + Uri.encode(num.trim().toString()))); | |
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) ; | |
startActivity(callIntent); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean isTablet(Context context) { | |
return (context.getResources().getConfiguration().screenL ayout | |
& Configuration.SCREENLAYOUT_SIZE_MASK) | |
>= Configuration.SCREENLAYOUT_SIZE_LARGE; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class activity extends Activity implements SimpleGestureListener { | |
private logskey detector; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
} | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
InputStream input; | |
try { | |
input = getAssets().open(fileName); | |
int size = input.available(); | |
byte[] buffer = new byte[size]; | |
input.read(buffer); | |
input.close(); | |
String text = new String(buffer); | |
} | |
catch (IOException e) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AlertDialog.Builder alert = new AlertDialog.Builder(this); | |
alert.setTitle("Title"); | |
alert.setMessage("Message"); | |
// Set an EditText view to get user input | |
final EditText input = new EditText(this); | |
alert.setView(input); | |
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static long back_pressed = 0L; | |
@Override | |
public void onBackPressed() | |
{ | |
if (back_pressed + 2000 > System.currentTimeMillis()) super.onBackPressed(); | |
else Toast.makeText(getBaseContext(), "Press once again to exit!", Toast.LENGTH_SHORT).show(); | |
back_pressed = System.currentTimeMillis(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int screenSize = getResources().getConfiguration().screenLayout & | |
Configuration.SCREENLAYOUT_SIZE_MASK; | |
switch(screenSize) { | |
case Configuration.SCREENLAYOUT_SIZE_LARGE: | |
Toast.makeText(this, "Large screen",Toast.LENGTH_LONG).show(); | |
break; | |
case Configuration.SCREENLAYOUT_SIZE_NORMAL: | |
Toast.makeText(this, "Normal screen",Toast.LENGTH_LONG).show(); | |
break; | |
case Configuration.SCREENLAYOUT_SIZE_SMALL: |
NewerOlder