Skip to content

Instantly share code, notes, and snippets.

View mancdevcarl's full-sized avatar

Carl mancdevcarl

  • MancDev
  • Manchester
View GitHub Profile
@mancdevcarl
mancdevcarl / gist:9f0d3230b4c381ce7a4d
Last active August 29, 2015 14:13
Simple Green Screen images for Android
//This demo app Assumes there are 2 jpg files on the sdcard in the root directory
public class MainActivity extends ActionBarActivity {
ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
public class MyAppClass extends Application
{
public static Typeface FONT_AWESOME;
public static FontAwesomeHelper FONT_AWESOME_HELPER;
@Override
public void onCreate()
{
super.onCreate();
@mancdevcarl
mancdevcarl / BarsFragment.java
Last active December 17, 2015 11:29
This fragment uses 4 vertical seekbars. Each bar is adjustable between 0% and 100%. As a bar is adjusted the other bars adjust in realtime so that the total of all bars always equals 100%
public class BarsFragment extends Fragment {
int[] positionsArray = new int[4];
VerticalSeekBar[] seekBarArray;
LinearLayout ll;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.barsfragment, container, false);
String myTag = getTag();
((MainActivity) getActivity()).setFragmentTag(myTag);
@mancdevcarl
mancdevcarl / gist:5624897
Last active December 17, 2015 14:29
Clipboard programatically
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label", shortUrl);
clipboard.setPrimaryClip(clip);
Toast toast = Toast.makeText(getApplicationContext(),"copied", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
} else {
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
@mancdevcarl
mancdevcarl / gist:5624906
Last active December 17, 2015 14:29
ACTION_SENDTO Intent SMS and Email
try {
if (v == findViewById(R.id.emailbtn)) {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO,Uri.fromParts("mailto", "@", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "TITLE");
emailIntent.putExtra(Intent.EXTRA_TEXT, "TEXT");
startActivity(Intent.createChooser(emailIntent, "Send email..."));
} else if (v == findViewById(R.id.smsbtn)) {
Uri uri = Uri.parse("smsto:");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "BODY");
@mancdevcarl
mancdevcarl / ListViewAdapter.java
Last active December 17, 2015 18:29
Custom Listview Example
public class ListViewAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<VideoObject> data;
private static LayoutInflater inflater = null;
public ImageLoader imageLoader;
Context cx;
public ListViewAdapter(Activity a, ArrayList<VideoObject> videoObjListParam) {
activity = a;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@mancdevcarl
mancdevcarl / gist:5663633
Created May 28, 2013 15:33
getRuntimeExec()
StringBuffer outputx = null;
try {
Process processx = Runtime.getRuntime().exec("/data/data/com.example.ffmpegencode/ffmpeg -loop_input -i /sdcard/go.jpg -i /sdcard/gohoubi.m4a -shortest -acodec copy /sdcard/goood.mp4");
BufferedReader in = new BufferedReader(new InputStreamReader(processx.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
Log.d("", "line");
}
Log.d("", "encoding...");
processx.waitFor();
find someDir/ -iname "*.flv" -exec ffmpeg -i {} -sameq -ar 22050 {}.mp4 ";" -ls
vlc * --sout '#transcode{vcodec=h264,vb=92,channels=1,ab=16,samplerate=1024,width=320}:standard{access=http,mux=ts,dst=:666/tv.mp4}' --random --sout-keep
awk -F'[ "]+' '$7 == "/" { ipcount[$1]++ }END { for (i in ipcount) {printf "%15s - %d\n", i, ipcount[i] } }' /var/log/apache2/access.log
ffmpeg -loop 1 -shortest -y -i img.jpg -i snd.wav -acodec copy -vcodec mjpeg out.avi
ls * |sort > play.txt
cat play.txt | while IFS= read -r f; do printf "%05d %s\n" "$RANDOM" "$f"; done | sort -n | cut -c7- >> play.m3u
sed -e 's/$/\nwf.mp4/' -i play.m3u
@mancdevcarl
mancdevcarl / gist:5716335
Last active December 18, 2015 03:09
Check if service is running using SharedPreferences
//**in the service (ServiceX)
public static boolean isRunning(Context ctx) {
sharedPref = ctx.getSharedPreferences("my_pref", MODE_PRIVATE);
return sharedPref.getBoolean("running", false);
}
private void setRunning(boolean running) {
sharedPref = getSharedPreferences("my_pref", MODE_PRIVATE);
SharedPreferences.Editor prefEditor = sharedPref.edit();
prefEditor.putBoolean("running", running);
prefEditor.commit();
@mancdevcarl
mancdevcarl / gist:5737023
Last active December 18, 2015 05:59
AsyncTask Callback Example
public class Act extends Activity {
OnTaskCompleted otc = new OnTaskCompleted() {
@Override
public void onTaskCompleted(String result) {
Log.d("onTaskCompleted", result);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);