Server implementation selector. AdMob banner in LauncherActivity(haters gonna hate)

This commit is contained in:
a1batross 2016-01-11 23:39:56 +03:00
parent c85c13b067
commit f165e4a312
6 changed files with 187 additions and 100 deletions

View File

@ -3,10 +3,12 @@
package="in.celest.xash3d.cs16client"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="5"/>
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="23"/>
<application android:label="@string/app_name"
android:debuggable="true"
android:icon="@drawable/ic_launcher">
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity android:name=".LauncherActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize">
@ -22,5 +24,10 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>-->
</application>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>

View File

@ -1,7 +1,8 @@
#!/bin/sh
ndk-build NDK_TOOLCHAIN_VERSION=4.8 NDK_DEBUG=1 V=0 -j8 APP_CFLAGS="-w"
ndk-build NDK_TOOLCHAIN_VERSION=4.8 NDK_DEBUG=0 V=0 -j8 APP_CFLAGS="-w"
ant debug
#jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ../myks.keystore bin/cs16-client-unsigned.apk xashdroid -tsa https://timestamp.geotrust.com/tsa
#/home/a1ba/.android/android-sdk-linux/build-tools/22.0.1/zipalign 4 bin/cs16-client-unsigned.apk bin/cs16-client.apk
adb install -r -f bin/cs16-client-debug.apk
#jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ../../myks.keystore bin/cs16-client-release-unsigned.apk xashdroid -tsa https://timestamp.geotrust.com/tsa
#/home/a1ba/.android/android-sdk-linux/build-tools/22.0.1/zipalign 4 bin/cs16-client-release-unsigned.apk bin/cs16-client.apk
#adb install -r -f bin/cs16-client-debug.apk
mv bin/cs16-client-debug.apk cs16-client-debug-`date +"%d-%m-%y-%H-%M"`.apk

View File

@ -8,4 +8,6 @@
# project structure.
# Project target.
target=android-13
target=android-23
android.library.reference.1=libs/google-play-services_lib

View File

@ -1,51 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="in.celest.xash3d.LauncherActivity"
android:id="@+id/layout_shortcut">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1.0">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/cmd_args_text"
android:id="@+id/textView_args" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cmdArgs" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/server_spinner_description"
android:id="@+id/serverSpinner_description"/>
<Spinner
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/serverSpinner"
android:layout_below="@+id/cmdArgs"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/cmdArgs"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:id="@+id/textView7"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:clickable="false" />
</LinearLayout>
</ScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/launch_button"
android:id="@+id/button_launch"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:onClick="startXash"/>
<EditText
android:onClick="startXash"
android:layout_column="6"
android:layout_gravity="right"
android:layout_weight="0.0" />
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cmdArgs"
android:layout_below="@+id/textView_args"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/textView_args"/>
ads:adSize="BANNER"
ads:adUnitId="@string/ad_unit_id"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/cmd_args_text"
android:id="@+id/textView_args"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"/>
<CheckBox
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/use_cs16nd"
android:id="@+id/usecs16nd"
android:layout_below="@+id/cmdArgs"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/cmdArgs"/>
</RelativeLayout>
</LinearLayout>

View File

@ -6,10 +6,22 @@
<string name="title_activity_launcher">LauncherActivity</string>
<string name="launch_button">Launch cs16-client!</string>
<string name="cmd_args_text">Command line arguments(experts only)</string>
<string name="use_cs16nd">Use CS16ND server(may differ from CS 1.6)</string>
<string name="server_spinner_description">Choose libserver implementation:</string>
<string name="not_found_msg">Nothing was found. Check your APK or choose another server</string>
<string name="not_found_title">Something got wrong...</string>
<string name="not_implemented_msg">This feature is not implemented yet</string>
<string name="not_implemented_title">Not implemented!</string>
<string name="ad_unit_id"></string> <!-- Не дам :P -->
<!--
<string name="text_shortcut">SoHL shortcut</string>
<string name="shortcut_button_save">Save shortcut</string>
<string name="gamedir">Mod directory</string>
<string name="shortcut_name">Shortcut name</string>-->
<string-array name="avail_servers">
<item>Nothing</item>
<item>cs16nd</item>
<item>YaPB over cs16nd</item>
<item>ReGameDLL_CS</item>
<item>YaPB over ReGameDLL_CS</item>
</string-array>
</resources>

View File

@ -1,98 +1,134 @@
package in.celest.xash3d.cs16client;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.content.Intent;
import android.widget.EditText;
import android.widget.CheckBox;
import android.widget.Spinner;
import android.widget.CompoundButton;
import android.widget.ArrayAdapter;
import android.content.ComponentName;
import android.content.pm.PackageManager;
import android.content.SharedPreferences;
import android.util.Log;
import com.google.android.gms.ads.*;
import java.io.File;
import in.celest.xash3d.cs16client.R;
public class LauncherActivity extends Activity {
// public final static String ARGV = "in.celest.xash3d.MESSAGE";
public final static String TAG = "LauncherActivity";
static EditText cmdArgs;
static SharedPreferences mPref;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
mPref = getSharedPreferences("mod", 0);
cmdArgs = (EditText)findViewById(R.id.cmdArgs);
static Spinner mServerSpinner;
static AdView mAdView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
mPref = getSharedPreferences("mod", 0);
cmdArgs = (EditText)findViewById(R.id.cmdArgs);
mServerSpinner = (Spinner) findViewById(R.id.serverSpinner);
mAdView = (AdView) findViewById(R.id.adView);
cmdArgs.setText(mPref.getString("argv","-dev 5 -log"));
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.avail_servers, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
mServerSpinner.setAdapter(adapter);
mServerSpinner.setSelection(mPref.getInt("serverSpinner", 0));
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("B1F9AE0E2DC2387F53BE815077840D9B")
.build();
mAdView.loadAd(adRequest);
}
public void startXash(View view)
{
public void startXash(View view)
{
SharedPreferences.Editor editor = mPref.edit();
String argv = cmdArgs.getText().toString();
editor.putString("argv", argv);
editor.putInt("serverSpinner", mServerSpinner.getSelectedItemPosition());
editor.commit();
editor.apply();
switch(mServerSpinner.getSelectedItemPosition())
{
case 0:
argv = argv + " -dll censored";
break;
case 1:
// Engine will load libserver.so by himself
break;
case 2:
String fullPath = getFilesDir().getAbsolutePath().replace("/files","/lib");
File yapb_hardfp = new File( fullPath + "/libyapb_hardfp.so" );
File yapb = new File( fullPath + "/libyapb.so" );
if( yapb_hardfp.exists() && !yapb_hardfp.isDirectory() )
argv = argv + " -dll " + yapb_hardfp.getAbsolutePath();
else if( yapb.exists() && !yapb.isDirectory() )
argv = argv + " -dll " + yapb.getAbsolutePath();
else
{
Log.v(TAG, "YaPB not found!");
AlertDialog.Builder notFoundDialogBuilder = new AlertDialog.Builder(this);
notFoundDialogBuilder.setMessage(R.string.not_found_msg)
.setTitle(R.string.not_found_title);
notFoundDialogBuilder.create();
return;
}
break;
case 3:
case 4:
AlertDialog.Builder notImplementedDialogBuilder = new AlertDialog.Builder(this);
notImplementedDialogBuilder.setMessage(R.string.not_implemented_msg)
.setTitle(R.string.not_implemented_title);
notImplementedDialogBuilder.create();
return;
}
Intent intent = new Intent();
intent.setAction("in.celest.xash3d.START");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
SharedPreferences.Editor editor = mPref.edit();
String argv = cmdArgs.getText().toString();
CheckBox enableCs16nd = (CheckBox) findViewById(R.id.usecs16nd);
editor.putString("argv", argv);
editor.commit();
editor.apply();
if(!(enableCs16nd.isChecked()))
argv = argv + " -dll censored";
else
{
String fullPath = getFilesDir().getAbsolutePath().replace("/files","/lib");
File yapb_hardfp = new File( fullPath + "/libyapb_hardfp.so" );
File yapb = new File( fullPath + "/libyapb.so" );
if( yapb_hardfp.exists() && !yapb_hardfp.isDirectory() )
{
argv = argv + " -dll " + yapb_hardfp.getAbsolutePath();
}
else
{
Log.v(TAG, yapb_hardfp.getAbsolutePath() + "not found!");
if( yapb.exists() && !yapb.isDirectory() )
{
argv = argv + " -dll " + yapb.getAbsolutePath();
}
else Log.v(TAG, yapb.getAbsolutePath() + "not found!");
}
}
if(cmdArgs.length() != 0) intent.putExtra("argv", argv);
if(cmdArgs.length() != 0)
intent.putExtra("argv", argv);
intent.putExtra("gamedir", "cstrike");
intent.putExtra("gamelibdir", getFilesDir().getAbsolutePath().replace("/files","/lib"));
startActivity(intent);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
//getMenuInflater().inflate(R.menu.menu_launcher, menu);
return true;
}
@Override
public void onResume() {
super.onResume();
if(mAdView != null)
mAdView.resume();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
@Override
public void onDestroy() {
if(mAdView != null)
mAdView.destroy();
//noinspection SimplifiableIfStatement
/*if (id == R.id.action_settings) {
return true;
}*/
super.onDestroy();
}
return super.onOptionsItemSelected(item);
}
@Override
public void onPause() {
if(mAdView != null)
mAdView.pause();
super.onPause();
}
}