This repository has been archived by the owner on Aug 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
/
index.php
204 lines (169 loc) · 7.54 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
/*
* Copyright 2012 Dallas Gutauckis
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Parcelabler
*
* An Android parcelabler creator
*
* @since 2012-02-22
* @author Dallas Gutauckis <dallas@gutauckis.com>
*/
// Basic autoloader
function __autoload( $class ) {
$path = 'include/' . $class . '.php';
if ( file_exists( $path ) ) {
require( $path );
}
}
spl_autoload_register('__autoload');
$file = '';
if ( isset( $_POST['file'] ) )
{
$file = trim( $_POST['file'] );
}
$postedFields = isset( $_POST['fields'] ) ? explode( ',', $_POST['fields'] ) : array();
?>
<html>
<head>
<link rel="stylesheet" href="stylesheets/bootstrap.min.css" type="text/css" charset="utf-8" />
<script type="text/javascript" src="javascripts/jquery.js"></script>
<script type="text/javascript" src="javascripts/jquery-ui.js"></script>
<title>parcelabler</title>
</head>
<body style="width: 100%">
<a href="https://github.com/dallasgutauckis/parcelabler"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png" alt="Fork me on GitHub"></a>
<div class="container">
<div class="content">
<h1>parcelabler</h1>
<em>by <a href="http://dallasgutauckis.com">Dallas Gutauckis</a></em>
<h6>for Android Parcelable implementations</h6>
<!--<h5>Love Android? We're hiring! Hit me up for more info: <a href="mailto:dallas@seatgeek.com">dallas@seatgeek.com</a></h5>-->
<!--h5>[NEW]: Also check out <a href="http://dallasgutauckis.com/2014/02/10/a-better-parcelabler/">this convenient IntelliJ/Android Studio plugin...</a></h5-->
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- parcelabler.com — header -->
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-7874761747975813"
data-ad-slot="4561417088"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<form method="POST">
<fieldset>
<div class="row">
<div class="span10">
<h3>Code</h3>
<textarea name="file" rows="20" class="span10"><?php echo htmlentities( $file ); ?></textarea>
<span class="help-block">Paste your full class definition into the box above to get the Parcelable implementation and options for removing fields for parceling. Don't worry, we don't save your code. A small example is available at <a href="http://dallasgutauckis.com/2012/01/20/parcelabler-for-implementing-androids-parcelable-interface">this blog post about parcelabler</a>.</span>
</div>
<div class="span6">
<h3>Fields</h3>
<ul class="inputs-list">
<?php
$codeBuilder = new CodeBuilder( $file );
$unsupportedFields = array();
if ( $file && $codeBuilder->getClass() ) {
$fields = $codeBuilder->getFields();
foreach ( $fields as $field ) {
$fieldName = $field->getName();
$isChecked = '';
$supportLevel = $codeBuilder->getSupportLevel( $field );
if ( $supportLevel != SupportLevel::Unsupported ) {
$isChecked = count( $postedFields ) == 0 || false === in_array( $fieldName, $postedFields ) || ( isset( $_POST['field'][$fieldName] ) && !!$_POST['field'][$fieldName] );
echo '<li>'
. '<label>'
. '<input type="checkbox" ' . ( $isChecked ? 'checked="checked"' : '' ) . 'name="field[' . $fieldName . ']" />'
. '<span>' . $fieldName . '</span></label></li>';
$_POST['field'][$fieldName] = $isChecked;
} else {
array_push( $unsupportedFields, $field );
}
}
}
echo '</ul>';
$unrecognizedFields = $codeBuilder->getUnrecognizedFields();
if ($file && $codeBuilder->getClass() && !empty($unrecognizedFields)) {
echo '<br/><div class="alert-message error">The following variables were not recognized (syntax error?):
<br/><br/><ol>';
foreach ($unrecognizedFields as $variable) {
echo '<li class="error-item">' . $variable . '</li>';
}
echo '</ol></div>';
}
if ($file && $codeBuilder->getClass() && !empty($unsupportedFields)) {
echo '<br/><div class="alert-message error">The following variables cannot be written to Parcel:
<br/><br/><ol>';
foreach ($unsupportedFields as $variable) {
echo '<li class="error-item">' . $variable->getType() . ' ' . $variable->getName() . ';</li>';
}
echo '</ol></div>';
}
if ($file && $codeBuilder->getClass()) {
$suspiciousTypes = array();
$fields = $codeBuilder->getFields();
foreach ( $fields as $field ) {
if ( $codeBuilder->getSupportLevel( $field ) != SupportLevel::Unsupported ){
if ( $codeBuilder->isTypeUnconditionallyParcelable($field->getType()) === false ) {
array_push( $suspiciousTypes, $field->getType() );
}
$typeParam = $field->getTypeParam();
if ( !empty($typeParam) && $codeBuilder->isTypeUnconditionallyParcelable($typeParam) === false ) {
array_push( $suspiciousTypes, htmlentities($typeParam) );
}
}
}
if (!empty($suspiciousTypes)) {
echo '<br/><div class="alert-message warning">Check that the following classes implement either Parcelable or Serializable.<br/>'
. 'Otherwise you\'ll get a RuntimeException.<br/><br/><ol>';
foreach ($suspiciousTypes as $type) {
echo '<li>' . $type . '</li>';
}
echo '</ol></div>';
}
}
echo '<input type="hidden" name="fields" value="' . implode( ',', array_keys( $codeBuilder->getFields() ) ) . '" />
</div>
</div>
</fieldset>
<div class="actions">
<input type="submit" name="submit" class="btn primary" value="Build" />
</div>
</form>';
if ( isset( $_POST['submit'] ) && ! $codeBuilder->getClass() ) {
echo '<div class="alert-message info"><strong>Try again...</strong> We really do need the full class definition (including the class name) to build this. I promise, we won\'t steal your code.</div>';
} else if ( isset( $_POST['submit'] ) ) {
$selectedFields = $_POST['field'];
if ( count( $selectedFields ) > 0 ) {
$code = htmlentities( $codeBuilder->getOutput( $selectedFields ) );
echo '<h3>Output</h3><div class="alert-message success"><strong>Great news!</strong> Your code was parsed, you had fields for parceling, and the implementation for Parcelable is below.</div><p>Add the <a href="http://developer.android.com/reference/android/os/Parcelable.html">Parcelable</a> class to yours and add the following methods.</p><pre>' . $code . '</pre>';
} else {
echo '<div class="alert-message error"><strong>Oh noes :-/</strong> It looks like you don\'t have anything for parceling. Maybe it\'s my fault -- <a href="http://github.com/dallasgutauckis">let me know</a>.</div>';
}
}
?>
</div>
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-401905-7', 'parcelabler.com');
ga('send', 'pageview');
</script>
</body>
</html>