Skip to content

Instantly share code, notes, and snippets.

@Arxhtects
Last active November 27, 2017 13:52
Show Gist options
  • Save Arxhtects/4dc080880ed4ec526ce0ab821241bb6a to your computer and use it in GitHub Desktop.
Save Arxhtects/4dc080880ed4ec526ce0ab821241bb6a to your computer and use it in GitHub Desktop.
Fake Android Terminal
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="10dip" />
<size android:height="14dip" />
<solid android:color="@color/terminal_text" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/terminal_background">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/console_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/terminal_text"
android:textColorLink="@color/terminal_text"
android:textSize="14dip" />
<EditText
android:id="@+id/text_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@+id/console_view"
android:background="@color/terminal_background"
android:imeOptions="actionDone"
android:inputType="text"
android:textColor="@color/terminal_text"
android:textColorLink="@color/terminal_background"
android:textCursorDrawable="@drawable/cursor_color"
android:textSize="14dip" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.pm.ActivityInfo;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView.*;
import android.widget.TextView;
import android.view.inputmethod.EditorInfo;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_terminal);
//setting the orientation to Portrait
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
EditText editText = (EditText) findViewById(R.id.text_input);
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_DONE) {
EditText editText = (EditText) findViewById(R.id.text_input);
TextView newText = (TextView) findViewById(R.id.console_view);
String string = editText.getText().toString();
//strings
String input_print = "\n"+"> "+string+"\n"; //> new line then input text
String problems = "No Command Found"; //No Command Found
String help = "Id Help But Im Usless";
//commands checks
newText.append(input_print);
if (string.contains("clear")) {
newText.setText(null);
} else if (string.contains("help")) {
newText.append(help);
} else {
newText.append(problems);
}
editText.setText("");
handled = true;
}
return handled;
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment