HashTableList entry = table [hash];

28 

Teks penuh

(1)

APPENDIX

CODING HASHTABLE DATA STRUCTURE

1. HashTableMain.java

1

package

com.example.revan.hashtable_playstore.HashTableHitung

;

2

/**

3

* Created by REVAN on 7/22/17.

4

*/

5

public class

HashTableMain {

6

private int

TABLE_SIZE;

7

private int size;

8

public HashTableList[] table;//

9

public HashTableMain(int ts) {

10

size = 0;

11

TABLE_SIZE = ts

;

12

table =

new HashTableList[TABLE_SIZE];

13

for (int i = 0; i < TABLE_SIZE; i++)

14

table[i] = null; // looping table tapi masih kosong

15

}

16

public

HashTableList[] getTable(){

17

return

table;

18

}

19

public int

getTABLE_SIZE(){

20

return

TABLE_SIZE;

21

}

22

public void

makeEmpty() {

23

for

(int i = 0; i < TABLE_SIZE; i++)

24

table[i] = null;

25

}

26

public void

insertvalue(int value)

27

{

28

int

hash = (value % TABLE_SIZE);

29

if (table[hash] == null)

30

table[hash] = new HashTableList(value);

31

else

32

{

33

HashTableList entry = table[hash];

34

while (entry.next != null)

35

entry = entry.next;

36

//while (entry.value == value)

37

//entry.value = value;

38

if (entry.value == value)

39

entry.value = value;

40

else

41

entry.next = new HashTableList(value);

42

}

43

size++;

(2)

44

}

45

public int

[] getLoc(int value) {

46

int

hash = (value % TABLE_SIZE);

47

int[] result = {0, 0};//00

48

int[] notFound = {100, 100};

49

int count = 0;

50

if (table[hash] != null) {

51

HashTableList entry = table[hash];

52

result[

0] = hash;

53

while (entry != null) {

54

if

(entry.value == value) {

55

result[1] = count;

56

//Log.i("index2", String.valueOf(count));

57

break;

58

}

else

59

count++

;

60

entry = entry.next;

61

}

62

return result;

63

} else return notFound;

64

}

65

public int[] getLoc2(int value) {

66

int hash = (value % TABLE_SIZE);

67

int[] result = {1000, 1000};//00

68

int[] notFound = {100, 100};

69

int count = 0;

70

if (table[hash] != null) {

71

HashTableList entry = table[hash];

72

while (entry != null) {

73

if (entry.value == value) {

74

result[0] = hash;

75

result[1] = count;

76

//Log.i("index2", String.valueOf(count));

77

break;

78

}

else

79

count++

;

80

entry = entry.next

;

81

}

82

return

result;

83

}

else return notFound;

84

}

85

public void

removevalue(int value) {

86

int

hash = (value % TABLE_SIZE);

87

if (table[hash] != null) {

88

HashTableList delEntry = null;

89

HashTableList entry = table[hash]

;

90

while (entry != null) {

91

if

(entry.value == value) {

92

if

(entry == table[hash])

93

table[hash] = entry.next;

94

else

95

delEntry.next = entry.next;//atau

entry.next

96

size--

;

(3)

97

}

else{

98

delEntry = entry;

99

}

100

entry = entry.next;

101

}

102

}

103

}

104

public void

printHashTable()

105

{

106

for

(int i = 0; i < TABLE_SIZE; i++)

107

{

108

HashTableList entry = table[i];

109

System.out.print(

"\nARRAY ["+ (i) +"] : ");

110

while (entry != null)

111

{

112

System.out.print(entry.value +" " + "|" + " ");

113

entry = entry.next

;

114

}

115

}

116

}

117

}

118

2. HashTableList.java

119

package

com.example.revan.hashtable_playstore.HashTableHitung

;

120

/**

121

* Created by REVAN on 7/22/17.

122

*/

123

public class

HashTableList {

124

public int value;

125

public HashTableList next;

126

HashTableList(int value)

127

{

128

this.value = value;

129

this.next = null;

130

}

131

}

132

(4)

CODING DRAWING

2. MainActivity.java

133

package

com.example.revan.hashtable_playstore

;

134

import

android.content.Context

;

135

import

android.content.Intent

;

136

import

android.content.SharedPreferences

;

137

import

android.graphics.Bitmap

;

138

import

android.graphics.Canvas

;

139

import

android.graphics.Color

;

140

import

android.graphics.Paint

;

141

import

android.graphics.PorterDuff

;

142

import

android.graphics.drawable.BitmapDrawable

;

143

import

android.os.Build

;

144

import

android.os.Bundle

;

145

import

android.os.CountDownTimer

;

146

import

android.support.annotation.RequiresApi

;

147

import

android.support.design.widget.FloatingActionButton

;

148

import

android.support.design.widget.Snackbar

;

149

import

android.view.View

;

150

import

android.support.design.widget.NavigationView

;

151

import

android.support.v4.view.GravityCompat

;

152

import

android.support.v4.widget.DrawerLayout

;

153

import

android.support.v7.app.ActionBarDrawerToggle

;

154

import

android.support.v7.app.AppCompatActivity

;

155

import

android.support.v7.widget.Toolbar

;

156

import

android.view.Menu

;

157

import

android.view.MenuItem

;

158

import

android.widget.Button

;

159

import

android.widget.EditText

;

160

import

android.widget.LinearLayout

;

161

import

android.widget.Toast

;

162

import

com.example.revan.hashtable_playstore.HashTableHitung.HashTable

List

;

163

import

com.example.revan.hashtable_playstore.HashTableHitung.HashTable

Main

;

164

public class

MainActivity

extends

AppCompatActivity

165

implements

NavigationView.OnNavigationItemSelectedListener {

166

private EditText textValue;

167

private EditText value_HashInput;

168

private EditText ETDelete;

169

private EditText ETSearch;

170

private Button saveButton;

171

private Button hashButton;

172

private Button tampil;

173

private Button DeleteButton;

(5)

174

private Button SearchButton;

175

private Button Reset;

176

public int height = 10;

177

public int varx_ExtendsSearch = 50;

178

public int panjangx_ExtendsSearch = 140;

179

public int vary_ExtendsSearch = 50;

180

public int panjangy_ExtendsSearch = 140;

181

public int varx_overlaySearch = 50;

182

public int panjangx_overlaySearch = 140;

183

public int vary_overlaySearch = 50;

184

public int panjangy_overlaySearch = 140;

185

public static final String Value = "valueKey";

186

public static final String MyPREFERENCES = "MyPrefs";

187

Canvas canvas

;

188

Paint overlay =

new Paint();

189

Paint extendShape =

new Paint();

190

Paint strokeSearch = new Paint();

191

Paint fillPaint =

new Paint();

192

Paint strokePaint = new Paint();

193

Paint TextArray = new Paint();

194

Paint panah = new Paint();

195

HashTableMain ht;

196

SharedPreferences sharedPreferences;

197

LinearLayout II;

198

B i t m a p b g = B i t m a p .createBitmap(720, 1280, Bitmap.Config.ARGB_8888);

199

@Override

200

protected void onCreate(Bundle savedInstanceState) {

201

super

.onCreate(savedInstanceState);

202

setContentView(R.layout.activity_main);

203

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

204

setSupportActionBar(toolbar);

205

textValue = (EditText) findViewById(R.id.value);

206

v a l u e _ H a s h I n p u t = ( E d i t T e x t ) findViewById(R.id.hash_value);

207

saveButton = (Button) findViewById(R.id.button_save)

;

208

h a s h B u t t o n = ( B u t t o n )

findViewById(R.id.hash_InputButton);

209

tampil = (Button) findViewById(R.id.tampil)

;

210

ETDelete = (EditText) findViewById(R.id.ET_Delete)

;

211

ETSearch = (EditText) findViewById(R.id.ET_Search)

;

212

DeleteButton = (Button) findViewById(R.id.BT_Delete)

;

213

SearchButton = (Button) findViewById(R.id.BT_Search)

;

214

Reset = (Button) findViewById(R.id.BT_Reset)

;

215

II = (LinearLayout) findViewById(R.id.linear)

;

216

sharedPreferences = getSharedPreferences(MyPREFERENCES

, Context.MODE_PRIVATE);

217

saveButton.setOnClickListener(new

View.OnClickListener() {

218

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)

219

@Override

220

public void

onClick(View view) {

221

fillPaint.setStyle(Paint.Style.FILL);

(6)

222

fillPaint.setColor(Color.parseColor("#DA70D6") );

223

strokePaint.setStyle(Paint.Style.STROKE);

224

strokePaint.setColor(Color.GRAY)

;

225

strokePaint.setStrokeWidth(5);

226

TextArray.setColor(Color.BLACK)

;

227

TextArray.setTextSize(

30);

228

f i n a l String strValue =

textValue.getText().toString();

229

SharedPreferences.Editor editor = sharedPreferences.edit();

230

editor.putString(Value, strValue);

231

i n t x =

Integer.valueOf(textValue.getText().toString()).intValue();

232

final int varx = 50;

233

int vary = 50;

234

int panjangx = 140;

235

int panjangy = 140;

236

int ArrayTextY = 100;

237

int ArrayTextX = 10;

238

final Canvas canvas = new Canvas(bg);

239

setCanvas(canvas)

;

240

setStrokePaint(strokePaint);

241

for (int y = 0; y < x; y++) { // DRAW CANVAS ARRAY AWAL

242

int Array = 0+y;

243

canvas.drawRect(varx, vary, panjangx, panjangy, fillPaint);

244

canvas.drawRect(varx, vary, panjangx, panjangy, strokePaint);

245

canvas.drawText(String.valueOf("["+Array+" ]"),ArrayTextX, ArrayTextY, TextArray);

246

vary = 10 + panjangy;

247

panjangy = panjangy + 100;

248

ArrayTextY = ArrayTextY + 100;

249

}

250

ht = new HashTableMain(x);

251

setHt(ht);

252

II.setBackground(new BitmapDrawable(bg));

253

Toast.makeText(MainActivity.this, "Finish",

Toast.LENGTH_LONG);

254

}

255

});

256

hashButton.setOnClickListener(new

View.OnClickListener() {

257

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)

258

@Override

259

public void

onClick(View v) {

260

i n t input_hash =

Integer.valueOf(value_HashInput.getText().toString()).intValue();

261

i n t x =

Integer.valueOf(textValue.getText().toString()).intValue();

262

int hashHitung = input_hash%x;

263

getHt().insertvalue(input_hash)

;

264

redrawCanvas()

;

(7)

265

Toast.makeText(MainActivity.this, input_hash + " MODULO " + x + " = " + hashHitung, Toast.LENGTH_LONG).show();

266

}

267

});

268

DeleteButton.setOnClickListener(new

View.OnClickListener() {

269

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)

270

@Override

271

public void onClick(View view) {

272

i n t remove_Hash =

Integer.valueOf(ETDelete.getText().toString()).intValue();

273

getHt().removevalue(remove_Hash);

274

redrawCanvas();

275

}

276

});

277

SearchButton.setOnClickListener(new

View.OnClickListener()

278

{

279

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)

280

@Override

281

public void onClick (View view){

282

redrawCanvas();

283

strokeSearch.setStyle(Paint.Style.STROKE);

284

strokeSearch.setColor(Color.RED);

285

strokeSearch.setStrokeWidth(5);

286

i n t search_Hash =

Integer.valueOf(ETSearch.getText().toString()).intValue();

287

getHt().getLoc2(search_Hash)

;

288

int LocY = getHt().getLoc2(search_Hash)[0];

289

final int LocX = getHt().getLoc2(search_Hash)

[1];

290

redrawCanvas()

;

291

if(LocX ==100 && LocY==100) {

292

Toast.makeText(MainActivity.this, search_Hash + " TIDAK DITEMUKAN ", Toast.LENGTH_LONG).show();

293

}

else{

294

//Toast.makeText(MainActivity.this, search_Hash + " DITEMUKAN " + " DI ARRAY " + LocY + " LIST " + LocX, Toast.LENGTH_LONG).show();

295

}

296

if(LocX ==1000 && LocY==1000) {

297

Toast.makeText(MainActivity.this, search_Hash + " TIDAK DITEMUKAN ", Toast.LENGTH_LONG).show();

298

}

else{

299

//Toast.makeText(MainActivity.this, search_Hash + " DITEMUKAN " + " DI ARRAY " + LocY + " LIST " + LocX, Toast.LENGTH_LONG).show();

300

}

301

varx_overlaySearch = 50;

302

panjangx_overlaySearch =

140;

303

vary_overlaySearch =

50;

304

panjangy_overlaySearch =

140 ;

305

for (int y_overlay = 0; y_overlay < LocY; y_overlay++) {

(8)

306

vary_overlaySearch = 1 0 + panjangy_overlaySearch;

307

panjangy_overlaySearch =

panjangy_overlaySearch + 100;

308

}

309

varx_ExtendsSearch = 50;

310

panjangx_ExtendsSearch = 140;

311

vary_ExtendsSearch = 50;

312

panjangy_ExtendsSearch = 140 ;

313

for (int y_overlay = 0; y_overlay < LocY; y_overlay++) {

314

vary_ExtendsSearch = 1 0 +

panjangy_ExtendsSearch;

315

panjangy_ExtendsSearch =

panjangy_ExtendsSearch + 100;

316

}

317

int

count = 2037;

318

height =

0;

319

CountDownTimer timer = new

CountDownTimer(count, 90) {

320

@Override

321

public void onTick(long

millisUntilFinished) {

322

height = height +(7*LocX);

323

redrawCanvas();

324

if (LocX >= 0) {

325

getCanvas().drawRect(50+height,va ry_ExtendsSearch, 140+height, panjangy_ExtendsSearch, strokeSearch );

326

}

327

else if (LocX == 0) {

328

getCanvas().drawRect(height, 30, 100+height, 100, strokeSearch );

329

}

330

II.setBackground(new

BitmapDrawable(bg));

331

}

332

@Override

333

public void

onFinish() {

334

}

335

};

336

timer.start()

;

337

if( L o c X = = 0)

getCanvas().drawRect(50+height,vary_ExtendsSearch, 140+height, panjangy_ExtendsSearch, strokeSearch );

338

}

339

});

340

Reset.setOnClickListener(

new View.OnClickListener() {

341

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)

342

@Override

343

public void

onClick(View view) {

344

getHt().makeEmpty();

345

Paint fillPaint =

new Paint();

346

final Paint strokePaint = new Paint();

347

fillPaint.setStyle(Paint.Style.FILL)

;

(9)

348

fillPaint.setColor(Color.parseColor("#da4897") );

349

Bitmap bg = Bitmap.createBitmap(720, 1280, Bitmap.Config.ARGB_8888);

350

int reset = 0;

351

ht = new HashTableMain(reset);

352

setHt(ht);

353

redrawCanvas();

354

int x = 0;

355

final int varx = 10;

356

int vary = 10;

357

int panjangx = 100;

358

int panjangy = 100;

359

final Canvas canvas = new Canvas(bg);

360

setCanvas(canvas)

;

361

setStrokePaint(strokePaint);

362

for (int y = 0; y < x; y++) { // DRAW CANVAS ARRAY AWAL

363

canvas.drawRect(varx, vary, panjangx, panjangy, fillPaint);

364

canvas.drawRect(varx, vary, panjangx, panjangy, strokePaint);

365

vary =

10 + panjangy;

366

panjangy = panjangy +

100;

367

}

368

LinearLayout II = (LinearLayout) findViewById(R.id.linear);

369

II.setBackground(

new BitmapDrawable(bg));

370

}

371

});

372

tampil.setOnClickListener(

new View.OnClickListener() {

373

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)

374

@Override

375

public void

onClick(View view) {

376

getHt().printHashTable();

377

redrawCanvas()

;

378

Toast.

makeText(MainActivity.this,

379

" NOTICE 1 : SET ARRAY FIRST" + "\n" +

380

" NOTICE 2 : DONT INPUT SAME VALUE", Toast.LENGTH_LONG).show();

381

}

382

});

383

DrawerLayout drawer = (DrawerLayout)

findViewById(R.id.drawer_layout);

384

ActionBarDrawerToggle toggle = new

ActionBarDrawerToggle(

385

t h i s , drawer, toolbar,

R.string.navigation_drawer_open, R.string.navigation_drawer_close);

386

drawer.setDrawerListener(toggle)

;

387

toggle.syncState()

;

388

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);

389

navigationView.setNavigationItemSelectedListener(

this);

390

}

(10)

391

@Override

392

public void

onBackPressed() {

393

DrawerLayout drawer = (DrawerLayout)

findViewById(R.id.drawer_layout);

394

if (drawer.isDrawerOpen(GravityCompat.START)) {

395

drawer.closeDrawer(GravityCompat.START);

396

}

else {

397

super

.onBackPressed();

398

}

399

}

400

@Override

401

public boolean

onCreateOptionsMenu(Menu menu) {

402

getMenuInflater().inflate(R.menu.main, menu);

403

return true;

404

}

405

@Override

406

public boolean

onOptionsItemSelected(MenuItem item) {

407

int

id = item.getItemId();

408

//noinspection SimplifiableIfStatement

409

if (id == R.id.action_settings) {

410

return true;

411

}

412

return super

.onOptionsItemSelected(item);

413

}

414

@SuppressWarnings("StatementWithEmptyBody")

415

@Override

416

public boolean

onNavigationItemSelected(MenuItem item) {

417

//Memeriksa untuk melihat item yang akan dilklik dan

melalukan aksi

418

switch (item.getItemId()) {

419

// pilihan menu item navigasi akan menampilkan pesan toast klik kalian bisa menggantinya

420

//dengan intent activity

421

case R.id.nav_camera:

422

I n t e n t a b o u t = new

Intent(getApplicationContext(), AboutActivity.class);

423

startActivity(about)

;

424

return true;

425

case R.id.nav_gallery:

426

I n t e n t i n f o = new

Intent(getApplicationContext(), UserGuideActivity.class);

427

startActivity(info);

428

return true;

429

case R.id.nav_share:

430

Toast.makeText(getApplicationContext(), "Share Telah Dipilih", Toast.LENGTH_SHORT).show();

431

return true;

432

case R.id.nav_send:

433

Toast.makeText(getApplicationContext(), "Send Telah Dipilih", Toast.LENGTH_SHORT).show();

434

return true;

435

}

436

return false;

437

}

(11)

438

public void

redrawCanvas(){

439

final int

varx = 50;

440

int vary = 50;

441

int panjangx = 140;

442

int panjangy = 140;

443

int varx_overlay ;

444

int panjangx_overlay ;

445

int vary_overlay ;

446

int panjangy_overlay ;

447

int hashinput_toTableY ;

448

int hashinput_toTableX ;

449

int panahstartX = 140;//100

450

int panahstartY = 90;//50

451

int panahstopX = 180;//135

452

int panahstopY = 90;//50

453

int panahatasX = 70;

454

int panahatasY = 90;

455

int panahatasYX = 195;

456

int panahatasXY = 180;

457

int panahbawahX = 110;

458

int panahbawahY = 90;

459

int panahbawahYX = 195;

460

int panahbawahXY = 180;

461

int panahlurusX = 180;

462

int panahlurusY = 70;

463

int panahlurus2X = 180;

464

int panahlurus2Y = 110;

465

int ArrayTextY = 100;

466

int ArrayTextX = 10;

467

getCanvas().drawColor(0, PorterDuff.Mode.CLEAR);

468

II.setBackground(new BitmapDrawable(bg));

469

if (getHt().getTable() == null){

470

Toast.makeText(t h i s , "null data", Toast.LENGTH_SHORT).show();

471

}

472

else {

473

HashTableList[] entry = getHt().getTable();

474

for (int i = 0; i < getHt().getTABLE_SIZE(); i++) {

475

HashTableList tempArray = entry[i];

476

int Array = 0+i;

477

fillPaint.setStyle(Paint.Style.FILL);

478

fillPaint.setColor(Color.parseColor("#DA70D6") );

479

strokePaint.setStyle(Paint.Style.STROKE)

;

480

strokePaint.setColor(Color.GRAY)

;

481

strokePaint.setStrokeWidth(

5);

482

panah.setStyle(Paint.Style.FILL)

;

483

panah.setColor(Color.GRAY)

;

484

panah.setStrokeWidth(6);

485

TextArray.setColor(Color.BLACK)

;

486

TextArray.setTextSize(30);

487

getCanvas().drawRect(varx, vary, panjangx, panjangy, fillPaint);

(12)

488

getCanvas().drawRect(varx, vary, panjangx, panjangy, strokePaint);

489

getCanvas().drawText(String.valueOf("["+Array+" ]"),ArrayTextX, ArrayTextY, TextArray);

490

ArrayTextY = ArrayTextY + 100;

491

vary = 10 + panjangy;

492

panjangy = panjangy + 100;

493

overlay.setStyle(Paint.Style.FILL);

494

overlay.setColor(Color.parseColor("#FFEFD5"));

495

extendShape.setStyle(Paint.Style.FILL);

496

extendShape.setColor(Color.parseColor("#DA70D6 "));

497

Paint Text = new Paint();

498

Text.setColor(Color.parseColor("#DA70D6"));

499

Text.setTextSize(30);

500

if(entry[i] != null) {

501

while (tempArray != null) {

502

varx_overlay = 50;

503

panjangx_overlay = 140;

504

vary_overlay = 50;

505

panjangy_overlay = 140;

506

final String HashValue = String.valueOf(tempArray.value);

507

hashinput_toTableY =

getHt().getLoc(tempArray.value)[0];

508

hashinput_toTableX =

getHt().getLoc(tempArray.value)[1];

509

for (int y_overlay = 0; y_overlay < hashinput_toTableY; y_overlay++) {

510

vary_overlay = 1 0 + panjangy_overlay;

511

panjangy_overlay =

panjangy_overlay + 100;

512

}

513

if

(hashinput_toTableX > 0) {

514

int shifting = hashinput_toTableX * 150;

515

i n t shiftingX =

(hashinput_toTableX-1) * 150;

516

i n t shiftingText = hashinput_toTableX * 150;

517

i n t shiftingY =

hashinput_toTableY * 100;

518

getCanvas().drawLine(panahstartX+ shiftingX,panahstartY + shiftingY,panahstopX+shiftingX,panahstopY+ shiftingY,panah);

519

getCanvas().drawLine(panahatasXY+

shiftingX,p a n a h a t a s X + s h i f t i n g Y,panahatasYX+shiftingX,panahatasY+ shiftingY,panah);

520

getCanvas().drawLine(panahbawahXY +shiftingX,panahbawahX+ shiftingY,panahbawahYX+shiftingX,panahbawahY+ shiftingY,panah);

521

getCanvas().drawLine(panahlurusX+

shiftingX,panahlurusY+ shiftingY,panahlurus2X+shiftingX,panahlurus2Y+ shiftingY,panah);

(13)

522

getCanvas().drawRect(varx_overlay

+ s h i f t i n g, vary_overlay, p a n j a n g x _ o v e r l a y + s h i f t i n g, panjangy_overlay, overlay);

523

getCanvas().drawRect(varx_overlay + s h i f t i n g, vary_overlay, p a n j a n g x _ o v e r l a y + s h i f t i n g, panjangy_overlay, strokePaint);

524

getCanvas().drawText(HashValue, varx_overlay + 30 + shiftingText, panjangy_overlay - 30, Text);

525

} else if (hashinput_toTableX == 0) {

526

getCanvas().drawRect(varx_overlay,

vary_overlay, panjangx_overlay, panjangy_overlay, overlay);

527

getCanvas().drawText(HashValue, varx_overlay + 30, panjangy_overlay - 30, Text);

528

}

529

tempArray = tempArray.next;

530

}

531

}

532

II.setBackground(new BitmapDrawable(bg));

533

}

534

}

535

}

536

public Canvas getCanvas(){

537

return canvas;

538

}

539

public void setCanvas(Canvas canvas){

540

this.canvas = canvas;

541

}

542

public void setStrokePaint(Paint strokePaint) {

543

this.strokePaint = strokePaint;

544

}

545

public HashTableMain getHt() {

546

return

ht;

547

}

548

public void

setHt(HashTableMain ht) {

549

this

.ht = ht;

550

}

551

}

CODING USER INTERFACE

1. AboutActivity.java

552

package

com.example.revan.hashtable_playstore

;

553

import

android.annotation.SuppressLint

;

554

import

android.support.v7.app.ActionBar

;

555

import

android.support.v7.app.AppCompatActivity

;

556

import

android.os.Bundle

;

557

import

android.os.Handler

;

558

import

android.view.MotionEvent

;

559

import

android.view.View

;

560

561

public class

AboutActivity

extends

AppCompatActivity {

(14)

562

563

private static final boolean AUTO_HIDE = true;

564

565

private static final int AUTO_HIDE_DELAY_MILLIS = 3000;

566

567

private static final int UI_ANIMATION_DELAY = 300;

568

private final Handler mHideHandler = new Handler();

569

private View mContentView;

570

private final Runnable mHidePart2Runnable = new Runnable() {

571

@SuppressLint("InlinedApi")

572

@Override

573

public void

run() {

574

575

mContentView.setSystemUiVisibility(View.SYSTEM_UI_ FLAG_LOW_PROFILE

576

| View.SYSTEM_UI_FLAG_FULLSCREEN

577

| View.SYSTEM_UI_FLAG_LAYOUT_STABLE

578

| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY

579

|

View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

580

| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

581

}

582

};

583

private View mControlsView;

584

private final Runnable mShowPart2Runnable = new Runnable() {

585

@Override

586

public void run() {

587

// Delayed display of UI elements

588

ActionBar actionBar = getSupportActionBar();

589

if (actionBar != null) {

590

actionBar.show();

591

}

592

mControlsView.setVisibility(View.VISIBLE);

593

}

594

};

595

private boolean mVisible;

596

private final Runnable mHideRunnable = new Runnable() {

597

@Override

598

public void

run() {

599

hide();

600

}

601

};

602

603

private final View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {

604

@Override

605

public boolean onTouch(View view, MotionEvent motionEvent) {

606

if (AUTO_HIDE) {

607

delayedHide(AUTO_HIDE_DELAY_MILLIS);

608

}

609

return false;

(15)

610

}

611

};

612

@Override

613

protected void

onCreate(Bundle savedInstanceState) {

614

super

.onCreate(savedInstanceState);

615

setContentView(R.layout.activity_about)

;

616

mVisible =

true;

617

m C o n t r o l s V i e w =

findViewById(R.id.fullscreen_content_controls);

618

mContentView = findViewById(R.id.fullscreen_content)

;

619

620

mContentView.setOnClickListener(new

View.OnClickListener() {

621

@Override

622

public void

onClick(View view) {

623

toggle();

624

}

625

});

626

}

627

@Override

628

protected void

onPostCreate(Bundle savedInstanceState) {

629

super

.onPostCreate(savedInstanceState);

630

631

delayedHide(

100);

632

}

633

private void

toggle() {

634

if

(mVisible) {

635

hide();

636

}

else {

637

show();

638

}

639

}

640

private void

hide() {

641

ActionBar actionBar = getSupportActionBar()

;

642

if (actionBar != null) {

643

actionBar.hide();

644

}

645

mControlsView.setVisibility(View.GONE);

646

mVisible = false;

647

// Schedule a runnable to remove the status and navigation bar after a delay

648

mHideHandler.removeCallbacks(mShowPart2Runnable)

;

649

mHideHandler.postDelayed(mHidePart2Runnable,

UI_ANIMATION_DELAY);

650

}

651

@SuppressLint("InlinedApi")

652

private void

show() {

653

// Show the system bar

654

mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_

LAYOUT_FULLSCREEN

655

| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);

656

mVisible =

true;

657

// Schedule a runnable to display UI elements after a delay

(16)

658

mHideHandler.removeCallbacks(mHidePart2Runnable)

;

659

mHideHandler.postDelayed(mShowPart2Runnable,

UI_ANIMATION_DELAY);

660

}

661

/**

662

* Schedules a call to hide() in [delay] milliseconds, canceling any

663

* previously scheduled calls.

664

*/

665

private void delayedHide(int delayMillis) {

666

mHideHandler.removeCallbacks(mHideRunnable);

667

mHideHandler.postDelayed(mHideRunnable, delayMillis);

668

}

669

}

2. SplashScreen.java

670

package

com.example.revan.hashtable_playstore

;

671

import

android.content.Intent

;

672

import

android.os.Handler

;

673

import

android.support.v7.app.AppCompatActivity

;

674

import

android.os.Bundle

;

675

import

android.view.Window

;

676

import

android.view.WindowManager

;

677

public class

SplashScreen

extends

AppCompatActivity {

678

private static int

splashInterval = 2000;

679

@Override

680

protected void

onCreate(Bundle savedInstanceState) {

681

super

.onCreate(savedInstanceState);

682

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

683

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FU

LLSCREEN,

684

WindowManager.LayoutParams.FLAG_FULLSCREEN)

;

685

setContentView(R.layout.activity_splash_screen)

;

686

new Handler().postDelayed(new Runnable() {

687

@Override

688

public void

run() {

689

// TODO Auto-generated method stub

690

Intent i = new Intent(SplashScreen.this, MainActivity.class);

691

startActivity(i); // menghubungkan activity splashscren ke main activity dengan intent

692

//jeda selesai Splashscreen

693

this.finish();

694

}

695

private void finish() {

696

// TODO Auto-generated method stub

697

}

698

}, splashInterval);

699

}

;

700

}

701

(17)

3. UserGuideActivity.java

702

package

com.example.revan.hashtable_playstore

;

703

import

android.annotation.SuppressLint

;

704

import

android.support.v7.app.ActionBar

;

705

import

android.support.v7.app.AppCompatActivity

;

706

import

android.os.Bundle

;

707

import

android.os.Handler

;

708

import

android.view.MotionEvent

;

709

import

android.view.View

;

710

711

public class

UserGuideActivity

extends

AppCompatActivity

{

712

713

private static final boolean AUTO_HIDE = true;

714

715

private static final int AUTO_HIDE_DELAY_MILLIS = 3000;

716

717

private static final int UI_ANIMATION_DELAY = 300;

718

private final Handler mHideHandler = new Handler();

719

private View mContentView;

720

private final Runnable mHidePart2Runnable = new Runnable() {

721

@SuppressLint("InlinedApi")

722

@Override

723

public void

run() {

724

725

mContentView.setSystemUiVisibility(View.SYSTEM_UI_ FLAG_LOW_PROFILE

726

| View.SYSTEM_UI_FLAG_FULLSCREEN

727

| View.SYSTEM_UI_FLAG_LAYOUT_STABLE

728

| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY

729

|

View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

730

| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

731

}

732

};

733

private View mControlsView;

734

private final Runnable mShowPart2Runnable = new Runnable() {

735

@Override

736

public void

run() {

737

738

ActionBar actionBar = getSupportActionBar()

;

739

if (actionBar != null) {

740

actionBar.show();

741

}

742

mControlsView.setVisibility(View.VISIBLE);

743

}

744

};

745

private boolean mVisible;

746

private final Runnable mHideRunnable = new Runnable() {

747

@Override

748

public void

run() {

(18)

749

hide();

750

}

751

};

752

753

private final View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {

754

@Override

755

public boolean onTouch(View view, MotionEvent motionEvent) {

756

if (AUTO_HIDE) {

757

delayedHide(AUTO_HIDE_DELAY_MILLIS);

758

}

759

return false;

760

}

761

};

762

@Override

763

protected void

onCreate(Bundle savedInstanceState) {

764

super

.onCreate(savedInstanceState);

765

setContentView(R.layout.activity_user_guide)

;

766

mVisible =

true;

767

m C o n t r o l s V i e w =

findViewById(R.id.fullscreen_content_controls);

768

mContentView = findViewById(R.id.fullscreen_content);

769

770

mContentView.setOnClickListener(new

View.OnClickListener() {

771

@Override

772

public void onClick(View view) {

773

toggle();

774

}

775

});

776

777

}

778

@Override

779

protected void onPostCreate(Bundle savedInstanceState) {

780

super.onPostCreate(savedInstanceState);

781

782

delayedHide(100);

783

}

784

private void

toggle() {

785

if

(mVisible) {

786

hide();

787

}

else {

788

show();

789

}

790

}

791

private void

hide() {

792

// Hide UI first

793

ActionBar actionBar = getSupportActionBar()

;

794

if (actionBar != null) {

795

actionBar.hide();

796

}

797

mControlsView.setVisibility(View.GONE);

798

mVisible =

false;

(19)

799

800

mHideHandler.removeCallbacks(mShowPart2Runnable)

;

801

mHideHandler.postDelayed(mHidePart2Runnable,

UI_ANIMATION_DELAY);

802

}

803

@SuppressLint("InlinedApi")

804

private void

show() {

805

mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_ FULLSCREEN

806

| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);

807

mVisible = true;

808

809

mHideHandler.removeCallbacks(mHidePart2Runnable);

810

mHideHandler.postDelayed(mShowPart2Runnable,

UI_ANIMATION_DELAY);

811

}

812

813

private void delayedHide(int delayMillis) {

814

mHideHandler.removeCallbacks(mHideRunnable);

815

mHideHandler.postDelayed(mHideRunnable, delayMillis);

816

}

817

}

4. activity_about.xml

818

<FrameLayout

xmlns:android="http://schemas.android.com/apk/res/android"

819

xmlns:tools="http://schemas.android.com/tools"

820

android:layout_width="match_parent"

821

android:layout_height="match_parent"

822

android:background="#ffffff"

823

tools:context="com.example.revan.hashtable_playstore.AboutA ctivity">

824

825

<pl.droidsonroids.gif.GifImageView

826

android:id="@+id/fullscreen_content"

827

android:layout_width="match_parent"

828

android:layout_height="match_parent"

829

android:src="@drawable/splashau"

830

/>

831

<FrameLayout

832

android:layout_width="match_parent"

833

android:layout_height="match_parent"

834

android:fitsSystemWindows="true">

835

<LinearLayout

836

android:id="@+id/fullscreen_content_controls"

837

style="?metaButtonBarStyle"

838

android:layout_width="match_parent"

839

android:layout_height="wrap_content"

840

android:layout_gravity="bottom|center_horizontal"

841

android:background="@color/black_overlay"

842

android:orientation="horizontal"

843

tools:ignore="UselessParent">

844

</LinearLayout>

Figur

table[i] = null; // looping table tapi masih
table[i] = null; // looping table tapi masih. View in document p.1

Referensi

Memperbarui...

Related subjects :